17.4 Basic Editing

When you have opened a file, you can of course move around in it with the cursor. The cursor keys and PgUp, PgDn do what you'd expect. Home and End jump to the beginning and end of the line. (In older versions, they would actually jump to the beginning and end of the buffer.) However, there are also Control and Meta (Alt) key combos that move the cursor around. Because you do not need to move your hands to another part of the keyboard for these, they are much quicker once you get used to them. The most important such commands are listed in Table 17-1.

Table 17-1. Basic Emacs Editing Commands

Command Result
C-b go one character back
C-f go one character forward
C-n go one line down
C-p go one line up
C-a go to the beginning of the line
C-e go to the end of the line
M-b go one word back
M-f go one word forward
M-} go one paragraph forward
M-{ go one paragraph backward
M-a go one sentence backward
M-e go one sentence forward
C-d delete the character under the cursor
M-d delete until the end of the current word
C-v go down one screen (i.e., PgDn)
M-v go up one screen (i.e., PgUp)
M-< go to the beginning of the buffer
M-> go to the end of the buffer
C-_ undo the last change (can be repeated); note that you actually have to type Shift+Control+hyphen for this.
C-k delete to end of line
C-s forward search
C-r backward search

Note that many Meta commands are parallel to the Control commands except that they operate on larger units: while C-f goes forward one character, M-f goes forward an entire word, etc.

Also note that M-< and M-> require you to type Shift+Alt+comma and Shift+Alt+dot respectively, since < and > are on Shift+comma and Shift+dot. (Unless of course you have a different keyboard layout from the standard US layout.)

Note that C-k deletes (kills, as it is commonly called) all the text after the cursor to the end of the line, but doesn't delete the line itself (i.e., it doesn't delete the final newline). It only deletes the line if there was no text after the cursor. In other words, in order to delete a complete line, you have to put the cursor at the beginning of the line, and then hit C-k twice: once to delete the text on the line, once to delete the line itself.