GNU Emacs Quick Reference Guide

Moving around in the buffer

  By char: By word: By line: By S-exp: By page:
Forward: C-f M-f C-n C-M-f C-v
Backward: C-b M-b C-p C-M-b M-v
Beginning:     C-a   M-<
End:     C-e   M->

Deleting/Killing (cutting text)

  By char: By word: By line: By S-exp: By region:
Forward: C-d M-d C-k C-M-k C-w
Backward: Del M-Del      

Note: Sometimes Del brings up Emacs Help. If it does, use C-h instead.

Characters that have been deleted (as opposed to killed) can only be restored by the undo command, either C-x u or C-_  (Ctrl-underscore).

In Emacs, cutting and pasting text is called killing and yanking. Killed items can be yanked back into the buffer at any point with the yank command, C-y . This is the preferred method of moving text. You can yank the text any number of times. M-y will bring back previous kills.

The region is the text between point (the cursor) and mark. You can set the mark at the point's current position by typing C-Space or C-@ . You can then move the point, leaving a region between point and mark.

Incremental searching

Forward: C-s
Backward: C-r

A prompt will open at the bottom of the screen. Type enough of a search string until an occurrence of the desired string appears in the window.

To stop the search, press Esc. To find the next occurrence of the string, press C-s or C-r again.

Note: C-s often causes problems with flow control. If you try to use C-s on a terminal with flow control, the screen will freeze until you press C-q . If you don't have flow control in your terminal connection, and C-s does not do anything in Emacs, it may be that C-s has been disabled because of this problem. Try entering:

  M-x unflow

String replacement

M-% executes the query-replace function. You will be prompted for two strings. Beginning at the point, Emacs will then search for and stop at every occurrence of the first string. Press the Spacebar to replace this instance of the first string with the second. Press Del to skip replacement for this occurrence. Press  !  (exclamation point) to replace all matches in the buffer. Press Enter to end the query-replace, or press  .  (period) to make a single replacement and stop.

Moving from buffer to buffer and window to window

C-x C-b Prints a list of the available buffers
C-x b Asks you which buffer to select
C-x o Moves you into the other window on the screen
C-x 1 (numeral 1) Deletes all windows except the one with the cursor

Reading/Saving files and exiting Emacs

C-x C-f Reads a file into Emacs
C-x C-s Saves the current buffer (See notes about C-s above)
C-x C-w Saves the current buffer with a different name (like "save as" in Word®)
C-x C-c Saves all modified buffers and exits Emacs

Accessing online help

C-h Displays help window
M-x help Displays help window (alternate method)
C-h t Shows the tutorial
C-h a Shows commands matching a string
C-h i Enters the Gnu Info documentation browser

More information

For more information, see the Emacs reference materials at:

  http://www.geek-girl.com/emacs/emacs.html

Also see:

© Nachum Danzig 23 Oct 2002