Emacs Cheat Sheet


Emacs is a very powerful editor, but it can be very intimidating at first. The following is a list of some of the more useful commands.

Every emacs command listed below is a combination of a modifier key and a character. Sometimes a command is invoked by entering two such modifier-character combinations. There are two modifier keys, Control and Meta. Control is the key labeled "Ctrl" on your keyboard. Meta is a key that does not exist on modern keyboards. To invoke Meta, you need press and release the Escape key, labeled "Esc" on your keyboard. As you enter a command, it will appear at the bottom of the screen, sometimes prompting you for additional information, as with the search command.

Emacs has many modes and capabilities, and it is quite easy to find yourself in a situation where emacs is doing something that is not what you intended. When this happens, you can return to the "normal" text entering mode by hitting Ctrl-g. Failing this, quit emacs and open it up again.

To open a file with emacs, type
emacs filename
at the Unix command line. If the file does not exist, emacs will create it for you.

emacs Commands

Ctrl-x Ctrl-s
Saves the current file to disk.
Ctrl-x Ctrl-c
Quits emacs.
Ctrl-g
Terminates the current emacs command entry, allowing you to continue editing the text or issue a new command. This command is useful when you have made a mistake at the emacs command line.
Ctrl-z
Suspends emacs and returns you to the Unix command line.
Ctrl-a
Move the insertion point to the beginning of the current line.
Ctrl-e
Move the insertion point to the end of the current line.
Ctrl-k
Removes text from the current insertion point to the end of the line. The text is stored in a paste buffer, from which it can be retrieved.
Ctrl-y
Pastes whatever is in the paste buffer into the file starting from the insertion point.
Ctrl-s
Searches for the text you enter at the emacs command line going forward.
Ctrl-r
Searches for the text you enter at the emacs command line going backward.
Meta-%
Replace the target text with something else. You will be prompted for the target text and its replacement. Hit the Enter key after supplying each of these values. After the replacement value has been entered, emacs will search for the next instance of the search text. You will then have to enter "y" or "n" to accept or reject the target.
Meta-<
Move the insertion point to the beginning of the file.
Meta->
Move the insertion point to the end of the file.
Ctrl-v
Scroll to next screen.
Meta-v
Scroll to previous screen.
Ctrl-v
Scroll to next screen.

C-_
Undo the last change.