Basic editing commands
One way that Emacs lets users work quickly and efficiently is by providing
high-level commands for moving around in, and manipulating, text. There are
commands that operate on characters, words, lines, sentences, paragraphs,
pages, function definitions, whitespace, and more. You can use them anywhere
you read or edit text: source code, web pages, shells, directory listings,
email messages, and so on.
Moving around in buffers
The most basic buffer movement commands move point (the cursor) by rows
(lines) or columns (characters):
C-f | Forward one character |
C-n | Next line |
|
C-b | Back one character |
C-p | Previous line | | | |
|
|
Here are some ways to move around in larger increments:
C-a | Beginning of line |
M-f | Forward one word |
M-a | Previous sentence |
M-v | Previous screen |
M-< | Beginning of buffer |
|
C-e | End of line |
M-b | Back one word |
M-e | Next sentence |
C-v | Next screen |
M-> | End of buffer |
|
|
When you get used to these keys, they're faster than their more familiar
equivalents in other applications (Home, End, Ctrl+Left, etc.) because you
don't have to move your hands from the touch typing position. And these keys
are far faster than using a mouse to move around in a buffer.
Emacs often provides additional commands for moving around in
context-specific ways (e.g. in source code, commands to move to the previous
or next function definition).
Many of the above commands move to a location relative to your current
position in the buffer, so you can use them repeatedly (e.g.
C-p C-p
C-p to move back three lines). You can use the
prefix argument
to save time:
C-u followed by a number and a movement command
repeats that command the specified number of times. You can also
use
M-[digit] instead of
C-u [digit]. If you
use
C-u without specifying a digit, the default is 4. Omitting the
digit can save time when you don't know precisely how many units you want to
jump anyway.
C-u 3 C-p | Back 3 lines |
C-u 10 C-f | Forward 10 characters |
M-1 M-0 C-f | Forward 10 characters |
C-u C-n | Forward 4 lines |
C-u C-u C-n | Forward 16 lines |
C-u C-u C-u C-n | Forward 64 lines |
|
You can jump directly to a particular line number in a buffer:
M-g g | Jump to specified line |
Searching for text is a handy way to move around in a buffer. Think of
search as just another facility for movement. When you're looking for
something specific, you can use incremental search to take you right there
instead of scanning by lines or pages. More about search later.
C-s | Incremental search forward |
C-r | Incremental search backward |