Introduction to EMACS. Harriet Borton Academic and Research Computing

Similar documents
Editors in Unix come in two general flavours:

Introduction to GNU Emacs

UNIX: Using PICO on Central UNIX

OFFICE OF INFORMATION TECHNOLOGY

Emacs Tutorial. Creating or Opening a File. Geog 405/605 Computer Programming for Environmental Research Fall 2018

VIP Quick Reference Card

Mastering Linux by Paul S. Wang Appendix: The emacs Editor

Getting Started With XEmacs

Introduction to the Emacs Editor

The Xemacs Editor. Overview

Word Processing 1. Using a computer for Writing. Spreadsheets

7.1 INTRODUCTION 7.2 STARTING Emacs 7.3 Emacs SCREEN Menu Bar Text Mode Menu Mode Line Echo Line

Emacs manual:

BEG 6. 50p. Getting Started with the Emacs Screen Editor. An introduction to the Emacs screen editor, which is available on Unix systems.

entity tomove over backward forward character C-b C-f word M-b M-f line C-p C-n go to line beginning (or end) C-a C-e sentence M-a M-e paragraph M- M-

Princeton University COS 217: Introduction to Programming Systems Emacs Reference and Tutorial

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Using the Zoo Workstations

Microsoft Office Word. Help. Opening a Document. Converting from Older Versions

Each time you start PastPerfect you will be presented with the main menu.

Lab 1: Using Oz/Mozart IDE

Eastside Literacy Tutor Support Word Processing Tutorial

Introduction to MS Word XP 2002: An Overview

EVE WORKSHOP A practical introduction to the Extensible VAX Editor (2nd Edition)

Using nu/tpu on UNIX Last revised: 1/28/00

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

Basic vi Commands. What is vi? To Get Into and Out Of vi

DOCUMENTATION CHANGE NOTICE

vi Primer Adapted from:

vi filename edit filename starting at line 1

Bok, Jong Soon

Word 2016 Tips. Rylander Consulting

Microsoft Word Part I Reference Manual

Word 2013 Beginning. Technology Integration Center

Using CRISP. I. CRISP Basics To create a new file, at the UNIX prompt type: cr newfilename

Understanding Word Processing

MICROSOFT WORD 2010 BASICS

Word 2010 Beginning. Technology Integration Center

! Emacs Howto Tutorial!

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Computer Programming Lecture 3 이윤진서울대학교

Lab 3, Part 1: Using Oz/Mozart IDE

GNU Info. for version 4.2, 23 March Brian J. Fox

Statistics 202A - vi Tutorial

Word - Basics. Course Description. Getting Started. Objectives. Editing a Document. Proofing a Document. Formatting Characters. Formatting Paragraphs

A beginner s guide to (GNU) Emacs 24

FILE MAINTENANCE COMMANDS

Microsoft Word 2007 on Windows

Getting Started with UNIX

Table of Contents Data Validation... 2 Data Validation Dialog Box... 3 INDIRECT function... 3 Cumulative List of Keyboards Throughout Class:...

Part 1 : Easy Working Writer for the IBM~PC &

Reference Services Division Presents WORD Introductory Class

Lecture- 5. Introduction to Microsoft Excel

Microsoft Office Word. Part1

Writing Practice Tool Guide

KEYBOARD SHORTCUTS AND HOT KEYS

Microsoft Word 2010 Guide

Highline Excel 2016 Class 13: One Lookup Value to Return Multiple Items: Array Formula

Tutorial 1: Unix Basics

Section 5: Editing Cells

The first time you open Word

STAR OFFICE WRITER. Lesson 1

Microsoft Word: Steps To Success (The Bare Essentials)

Microsoft Word Introduction

Lesson 13 Editing and Formatting documents

PS TEXT EDIT and PS TEXT FORMAT User s Guide

Text Editors for Programmers. Dr. Prasad Kulkarni Michael Jantz Jamie Robinson

Answers to Even- Numbered Exercises

Computer Nashua Public Library Introduction to Microsoft Word 2010

You ll notice at the bottom of the file menu there is a list of recently opened files. You can click a file name in the list to re-open that file.

Corel Ventura 8 Introduction

INTRODUCTION TO VIM. John Kerl University of Arizona Department of Mathematics Software Interest Group September 7, 2005

SKILL AREA 210: USE A WORD PROCESSING SOFTWARE. Lesson 1: Getting Familiar with Microsoft Word 2007 for Windows...5

Menu Symbols. Menu Symbol. Key on Keyboard

Word 2007/10/13 1 Introduction

OU EDUCATE TRAINING MANUAL

Indispensable tips for Word users

Complete List of Windows 8 Keyboard Shortcuts Keyboard Shortcuts for Desktops

Microsoft Word 2010 Lesson Plan

VI Commands Cheat Sheets

Computer Networks Vim and Emacs. Seongjin Lee

Intro. To Unix commands. What are the machines? Very basics

Word 1 Module 2. Word 1. Module 2

Introduction to Microsoft Word 2010

WORD PROCESSING ASSIGNMENT # 1 ~ FILENAME: FONTS

Using Microsoft Word. Paragraph Formatting. Displaying Hidden Characters

Opening Microsoft Word. 1. Double click the Word 2016 icon on the desktop to launch word.

Introduction to Microsoft Office PowerPoint 2010

Microsoft Word Introduction to Word Processors

Phil Sung. Special thanks to Piaw Na and Arthur Gleckler

Using the Vi Text Editor

Published by SDL International ( Copyright SDL International. All rights reserved. Documentation for SDLX2004.

Microsoft Word 2011 Tutorial

WAAT-PivotTables Accounting Seminar

239 Excel Keyboard Shortcuts

Getting Started With UNIX Lab Exercises

C D WARD AND ASSOCIATES LIMITED

Basic Microsoft Word

COMPILED BY: WESLEY M. NYANDIKA 1

WORD BASICS: MICROSOFT OFFICE 2010

Transcription:

Introduction to EMACS Harriet Borton Academic and Research Computing

Contents Starting Emacs 2 Parts of the Emacs Screen 3 Basic Editing 4 Entering text 4 Moving around in a file 4 Deleting text 4 Undoing Changes 4 Aborting a command 4 Emacs and X-Windows 5 Exiting and Saving a File 6 Keys (Emacs conventions) 7 Using Keys to Move Around in File 8 Cut (or Copy) and Paste 9 Define a region 9 Cut or Copy the region to buffer 9 Paste to new location 9 Searching 10 Replacing Text 11 Global replacement 11 Query replacement 11 Spelling Checking 12 Modes 13 Other Useful Commands 14 Reformatting a paragraph 14 Centering 14 Numeric arguments 14 Inserting a file 14 On-line Help 15 Customizing Emacs 16 Command Summary 17

For this class, first create two files to play with: 1) Bring up a UNIX window. 2) Enter the two commands: cp /dept/arc/training/emacs/sample.txt sample.txt cp /dept/arc/training/emacs/sample2.txt sample2.txt Starting Emacs To create a new file or edit an existing file, you enter a UNIX command of the form: emacs filename substituting the name of your file for filename. On a UNIX workstation, emacs will open its own X window. Now, edit your your sample file by issuing the command: emacs sample.txt & NOTE: If you append the & to your command, you may continue to issue other commands in your UNIX window while Emacs is running. Always use the & if you are at a UNIX workstation Do not use the & if you are accessing UNIX remotely. 1

Buffers In Emacs, you are never editing the actual file; you are editing a copy, called a buffer. The Emacs window is your view of a buffer. When you save, you write the buffer to the file. Emacs can split the screen into more than one window to view different buffers at the same time. The Parts of an Emacs Screen 1. Top (or main buffer): Holds a copy of the file contents. 2. The status line (bottom of screen): --(unmodified) **(modified) %%(read-only) File name (or buffer name) The mode (more on this later) The line number your cursor is on Where you are in the file (top, bottom, %) 3. The echo line or mini-buffer (under status line). Used for issuing commands or displaying messages. 2

Basic Editing Entering text Just start typing. If the line becomes longer than width of the window, Emacs will put a \ in the right-most column and move to the next line. By default, you are in insert mode. Moving around in a file Use the arrow keys to move the cursor. Use Page Down and Page Up to move forward and backward by one screen. Use Home and End to move to beginning and end of file. Making New lines Press return at the end of a line to insert a new line after it. Press return at the beginning of a line to insert a new line before it. Press return in the middle to split a line. 3

Joining two lines Move the cursor to beginning of 2nd line. Press the Delete or Backspace key. Deleting text Delete or Backspace removes character just before cursor. Control-d deletes character at the cursor. Control-k deletes from the cursor to the end of the line. Undoing changes Press Control-x u to undo last change. Repeat to undo earlier changes. (unlimited undo) Aborting a command Pressing Control-g can get you out of trouble. 4

Emacs and X-Windows Menus and Cursor Placement The menu bar at the top of the window makes it easy to perform common tasks, such as editing, saving, quitting and finding help. You can move the cursor location by pointing the mouse and clicking the left mouse button. Selecting and copying Holding down the left mouse button, drag over the region to be selected. The selected region will be highlighted temporarily. Or, click the left mouse button at start of text you wish to select. Then click the right button after the last character you wish to copy. The text to be copied is now selected. To copy the selected text, position the cursor anywhere inside any X-window on the screen and press the middle button. 5

Exiting and Saving a File To leave Emacs: Type C x C c. Emacs will ask: Save file filename? (y or n) If you respond y, your changes will be saved and Emacs will quit. The previous version of your file will be also be saved. The back-up file will have the same name with a tilde ( ) at the end. If you respond n, Emacs will ask: Modified buffers exist; exit anyway? (yes or no) Respond yes (type the whole word) to exit without saving changes. If Emacs has done an autosave (which it does from time to time) this version of your file will also be saved. The filename will have a # character at each end. To save without exiting: Type C x C s. Emacs will respond: Wrote filename where filename is the absolute path of your file. 6

Exercise 1 Edit the filesample.txt What is the line number of the last line of the file? (Hint: use Page Down or End key and the arrow keys.) Return to top of file and change the title from Rescuing Yourself in Emacs to How to Get Out of Trouble. Put the title back the way it was (without retyping it). When using X-windows, what can you use the middle mouse button for? Select the text in parentheses at the top of the file and paste it at the end. What Ctrl sequence can delete an entire line? Use this sequence twice to delete the first two lines of the file. Exit emacs without saving changes. 6-1

Keys Conventions for indicating key sequences C The Control key Hold down. M The Meta key is different on different systems: the Alt key on IBMs and SGIs, the diamond key on Suns. The Escape key (E ) works on all systems. Press it and release. Some key concepts C key or E key Action performed immediately. Example: C d deletes character at cursor. E k deletes from cursor to end of sentence. C x... Execute two-key function. Action performed immediately when next character is entered. Example: C x u undoes last change. E x Cursor to mini-buffer. Enter command and press Return. Example: E x auto-fill-mode toggles word wrap on & off. 7

Using Keys to Move Around Alternatives to arrow keys C n and C p: next and previous line C f and C b: forward and back 1 character E f and E b: forward and back 1 word C a and C e: beginning and end of line E a and E e: beginning and end of sentence Alternatives to PgDn, PgUp, Home, End C v and E v: forward and back 1 screen E < and E >: beginning and end of file Using line numbers E x goto-line: go to specific line number (type line number, press Return) 8

Cut (or Copy) and Paste Not dependent on X-windows 1. Define a region A region is the text between the mark and the point. To define a region, you first set a mark at the beginning and then move your cursor to end. (The point is where your cursor currently is.) Move your cursor to the beginning of region. C Space (or C @): set a mark. Move your cursor (the point) to end of region. 2. Cut or copy the region to buffer C w: Cut the region to the cut buffer. or E w: Copy the region to the cut buffer 3. Paste to new location Move cursor to where the text is to be inserted. C y: Yank text from the cut buffer and paste in new location. 9

Searching C s, then type the text. Searches forward. C r, then type the text. Searches backward. Continue to search for the text further on in the file by re-entering C s or C r. Press Enter to leave search mode. C g: Abort the search. Some notes: The search begins when you type the first character; moves on as you continue typing. Searches ignore the case of the text. You can also search for a sequence of one or more words, regardless of how they are separated (e.g., multiple spaces or linebreaks): C s [RET] C w word word word [RET] Note to remote users: Some communications equipment uses C s for communications flow control (Xon/Xoff), which renders C s unusable for searches. Use C r (reverse search) instead. (If you press C s by mistake, press C q to unfreeze your session.) 10

Replacing Text Global replacement To replace all occurrences of a string: Move cursor to top of file. Type E x, replace-string. Press Return. Type the text to be replaced, press Return. Type the new text, press Return. Query replacement To be queried at each occurrence of the string: Move cursor to top of file. Type E % Type the text to be replaced, press Return. Type the new text, press Return. At each occurrence, Emacs will ask whether you want to replace the string. Some responses are: y change this one n leave this one unchanged! change all the rest without prompting q abort the replace command 11

Exercise 2 Edit the filesample.txt On what line number is the last occurence of the word Emacs? (Hint: use the forward search key sequence.) Find the phrase, It is simple. What line number does it end on? Replace all occurences of Emacs with Gnu Emacs. What happens if you don t return to the beginning of the file before trying to do this? How many sentences in the first paragraph? (Hint: How many times must you press Esc e to reach the end?) Pretend you are not using X-windows (i.e., you can t drag the mouse to highlight and you have no middle mouse button), and move (not copy) the text in parentheses at the top of the file to the end of the file. Start by pressing Esc x and go to the line number you found for the last occurence of Emacs. (Is Emacs still on that line?) Exit emacs without saving changes. 11-1

Spelling Checking On RCS Unix systems, the Ispell spelling checker is built into Emacs. To use it: E x ispell-buffer or From Edit menu, select spell, then buffer You can also choose to check a word or a region. In addition to its own dictionary, ispell will use your personal dictionary, called by default.ispell words. To use a personal dictionary, create an empty file in your home directory called.ispell words. Ispell will display a wrong word at the top of the screen, along with a numbered list of possible replacements. To replace the word, type the number of the replacement you want. Other responses are: R You ll be prompted to replace the word. Space Accept the word this time only. A Accept word for the rest of this ispell session. I Accept word and update private dictionary. Q Quit Ispell. To find out more about ispell, see the man page. 12

Modes Major modes Emacs uses modes that customize editing for text of a particular sort. The mode often adds additional keys and commands that help with the editing. Some examples: fundamental-mode (the default) text-mode indented-text-mode tex-mode c-mode fortran-mode Use E x mode-name Return to switch among modes. The name of the mode is displayed at the bottom of the screen following the filename. Use C h m to display help about current mode. Minor Modes Minor modes do not affect the special commands of major modes. Some examples: auto-fill-mode (for word wrap) overwrite-mode (instead of insert mode) 13

Other Useful Commands Reformatting a paragraph Use the following anywhere within the paragraph: E q: reformat C u E q: reformat and right justify Centering If you are in text-mode, you can center a line: E s: center current line Inserting a file Place cursor where you want to insert file. Press C x i Type filename in mini-buffer, press Return. Note you can use / to refer to your home directory. Word Completion Emacs will try to complete partially typed file and command names. After typing a few characters of a command or file name, press the Tab key to try completion. 14

On-line Help C h: Enters help mode.* C h C h: Displays summary of help commands. C h F: Displays the Emacs FAQ. C h t: Starts the Emacs tutorial. C h a: After you enter a string, Emacs gives a list of commands that contain that string. For example, if you enter search, Emacs displays a list of searching commands. To clear the help text window: C x 1 (in main window) if window is split screen C x k followed by Return to kill full screen help There is a large on-line manual. To view it, enter: xdvi /campus/gnu/emacs/19.34/common/doc/emacs *Note you may also enter Emacs help mode by typing E x help, followed by Return. This may be helpful for remote use on systems where C h is set to perform the backspace function. 15

Customizing Emacs When it starts up, Emacs reads a file called.emacs (if there is one) in your home directory. Below are some commands you might want to put in this file. The lines beginning with ;;; are comments. (A sample.emacs file that contains these and a few more commands is on RCS in the file: bortonh/public/dotemacs.) ;;; start up using text-mode (setq default-major-mode text-mode) ;;; turn on word wrap when in text mode (setq text-mode-hook turn-on-auto-fill) ;;; set fill column to 75 (default is 70) (setq default-fill-column 75) For SecureCRT ;;; Make Home, End, PageUp, PageDown keys work: (load securecrt ) NOTE: Also do the following on the SecureCRT menu: Options > Session Preferences... > Emulation Tab Then in the box for Keyboard mapping: select VT220 For LaTeX Users ;;; Load Auctex: (require tex-site) ;;; List printers for the Print option in Command menu: (setq TeX-printer-list (( vclw ) ( vcpap3 ) ( vc200ovr ))) 16

Exercise 3 Edit the filesample2.txt What major mode are you using? Center the first two lines in the file. Will the method you used work in a file whose name does not end in.txt? Explain: Find the misspelled word in the file and correct it. What was it? Place the cursor in each of the following paragraphs and reformat it so the lines are not so uneven. Turn on auto-fill-mode (a minor mode). (Try command-name completion by using the Tab key.) At the end of the file, type a few new lines to observe word wrap. Leave emacs without saving changes. 16-1

Summary of Basic Emacs Commands Starting and Leaving Emacs emacs filename [&] start Emacs C x C c leave Emacs C x C s save file without leaving Emacs Bailing Out C x u (or Control ) undo last change C g abort a command Cursor Movement C n next line C p previous line C f forward 1 character C b back 1 character Ef forward 1 word Eb back 1 word C a beginning of line C e end of line Ea beginning of sentence Ee end of sentence Moving Around in File C v forward 1 screen Ev back 1 screen E < beginning of file E > end of file E x goto-line go to specific line number Deleting Text Delete (or Backspace) delete character before cursor C d delete character at the cursor C k delete from the cursor to the end of the line Ek delete from the cursor to the end of the sentence Cut, Copy and Paste C Space (or C @) set a mark C w Cut the region to the cut buffer Ew Copy the region to the cut buffer C-y Yank text from the cut buffer and paste in new location Search and Replace C s initiate forward search C r initiate backward search C s, press RET, C w initiate search for multiple words E x replace-string global replace E% query replace Miscellaneous Commands Eq reformat paragraph C u E q reformat and right justify paragraph E x auto-fill-mode toggle word-wrap on/off E x text-mode switch to text mode Es center a line (text mode only) C-u n specify number for next command C x i insert a file C h Enter help mode (E x help Return also works; helpful for remote access)