Emacs Handout - J. Maybury -------------------------- To start emacs you type: emacs on some machines you will need to type: emacs -nw at the UNIX prompt (%). is the name of the file you wish to edit. When you do this emacs will start up and will COPY the contents of the file into the work buffer (see below). NOTE: does not actually appear between < and > - it is purely a way for saying you can "substitute" <...> with a filename. If does not exist emacs will start editing a new empty/blank file by that name. In emacs commands are given by using combination or sequence keys C-x (also known as ^x or control-x) must be done in combination this means you must press AND HOLD down the control key and then press x ONCE. M-x (also known as meta-x) (usually escape-x) must be done in sequence this means you must press AND RELEASE the escape key and then press the x key ONCE. Note: on some computers the escape key may not work as the meta key and there is a special key with a DIAMOND on it - usually it's near the spacebar - try this one (it works sorta like the control key - hold it down when using it). One important combination is C-g, if you ever run into trouble try pressing C-g several times and usually it will get you back to the main buffer. Screen Parts - when in emacs the screen has several parts: 1) The work buffer screen - this is where all the text of the file you are editing appears. 2) The cursor - this is the point where any characters you type will be inserted or deleted. 3) The mode line - this is the line right above the bottom of the screen that displays information related to the file, such as a) the filename b) the current line the cursor is on c) the amount displayed top to bottom (in %) and d) whether or not the file has been modified (stars mean it has been). 4) The mini-buffer - this is the very bottom line of the screen. It is where any brief information will be displayed (such as when an autosave occurs). Also it is where you will enter any special commands (such as goto-line). To get into the mini-buffer type Meta-x (M-x). To get out of the mini-buffer type Cntrl-g (C-g). Commands to save the file and/or leave emacs: save-buffers-kill-emacs -- use C-x C-c this command will ask you to save changes (if you have made any) and then it will leave emacs. write-buffer-to-file -- use C-x C-w this command will ask for the name of the file to write (save) to and then will save the contents of the work buffer to that file NOTE: it will destroy whatever was in the file that you write to. save-buffer-to-file -- use C-x C-s this command will save the contents of the work buffer to the file that you are currently editing. Commands to move around the work buffer: arrow keys normally work to move one character (left or right) or one line (up or down) at a time. C-p will do the same as the up arrow (think of it as C-previous). C-n will do the same as the down arrow (think of as C-next). C-f will do same as right arrow (think of as C-forward). C-b will do same as left arrow (think of as C-back). M-b will move you one WORD back (instead of one character). M-f will move you one WORD forward (instead of one character). C-a will move you to the beginning of the current line think that a is the beginning of the alphabet. C-e will move you to the End of the current line think of e as standing for End. M-v will move you to the previous screen C-v will move you to the next screen M-< will move you to the beginning of the file (note press then -<) M-> will move you to the end of the file M-x goto-line will move you to any line you want Deleting, cutting and pasting: C-d delete-char - deletes the character currently "under" the cursor or - deletes character currently "before" the cursor M-d kill-word - deletes one word forward M- backward-kill-word - deletes one word forward C-k kill-line - deletes from the cursor to the end of the line (note if you want to delete the whole line press C-a to get to the beginning of the line first then C-k) Also you can keep pressing C-k to delete multiple lines M-# C-k (where # is some positive integer) will do C-k # times. M-# is a general multiplier C-y yank - takes the most recent thing "killed" out of the KILL-RING and pastes it where the cursor currently is. M-y yank-pop - related to C-y but it "pops" the most recent thing out of the KILL-RING The kill-ring can hold up to 30 pieces of "killed" information and using M-y allows you to scroll through what is in the kill-ring until you find the piece you want. Any command that has kill in its full name will put text into the kill-ring (so C-d which deletes a character will NOT put text into the kill-ring because it's full name is delete-char which does not contain the word kill). Blocking text: C-@ set-mark-command (note you have to press and hold then also press and hold then finally press @ (2) once). - sets an "invisible" marker where the cursor currently is you can then use this marker to delete a block of text. C-x C-x exchange-point-and-mark - this will show you where the mark is currently placed (this is VERY useful if you will ever use the mark) - it actually moves the cursor (point) to where the mark is and then moves the mark to where the cursor (point) was. C-w kill-region - deletes the "block" (region) of text between the cursor and the invisible mark. M-w kill-ring-save - copies the "block" (region) of text between the cursor and the invisible mark into the kill-ring. Undo commands: C-_ undo - undoes the very last change you made if done repeatedly it will continue to undo changes until there are no changes left to undo. C-x u advertised-undo - acts just like C-_ M-x revert-buffer - this will put the file back the way it was before any changes were made (only do this if you are sure about destroying all your work). Searching: C-s isearch-forward - will search forward for a word (you type the word down in the mini-buffer). C-r isearch-backward - just like C-s but searches backwards instead.