Scrolling happens automatically if you type any motion command that takes you beyond the limits of the text currently displayed. For example, if you are on the last line of the screen and press C-n, Emacs scrolls forward. Similarly, if you are at the top of the screen and press C-p, Emacs scrolls backward.
You often want to move all the way to the beginning or the end of a file. Type M->or press Endto go to the end of a buffer. To go to the beginning, type M-<or press Home. It may help you to remember that > points to the end of the buffer, and < points to the beginning of the buffer.
There are two more ways to move around that may come in handy. M-x goto-line Enter n Entermoves the cursor to line n of the file. Of course, Emacs starts counting lines from the beginning of the file. Likewise, M-x goto-char Enter n Entergoes to the n th character of the file, counting from the beginning. In both cases, n is a number.
For programmers, these commands are useful because many compilers give error messages like Syntax error on line 356
. By using these commands, you can move easily to the location of your error. There are some more sophisticated ways to link Emacs with error reports from compilers and other programs. In addition, several other cursor motion commands are applicable only when you are editing programs (see Chapter 9for details).
Now let's learn some efficiency tricks. Emacs lets you repeat any command as many times as you want to. First, you can repeat a command any number of times by pressing M- n before the command, where n is the number of times you want to repeat it. This command is called the digit-argumentcommand.
You can give M- n a large argument if you want it to repeat the command many times. For example, let's say you are editing a large file of 1000 lines. If you typed M-500 C-n, the cursor would move down 500 lines, to the halfway point in the file. If you give M- n a larger argument than it can execute, it repeats the command as many times as possible and then stops.
There's another multiplier command you can use, too: C-u(the universal-argumentcommand). You can give C-uan argument just like you do M- n . Typing either M-5or C-u 5repeats the command that follows five times. But unlike M- n , C-udoesn't need an argument to repeat commands. With no argument, C-uexecutes the next command four times. If you type C-u C-u, it executes the command 16 times. In this way, you can stack up C-u's to make commands execute many times: 16, 64, 256, and so on. [11]
2.1.4 Centering the Display
C-l, the recentercommand, puts the current line in the center of the window vertically. This feature is useful if you're typing at the bottom or the top of the display. Typing C-lquickly moves the material that you care about to the middle of the display, where it is easier to see the full context.
C-lalso redraws the display, if for any reason it appears obscured or contains random characters. This doesn't happen as often as it used to when we used terminals, but it can be a handy thing to know about, especially if you find yourself using Emacs remotely in a terminal interface.
Table 2-2lists cursor movement commands. If the command is mnemonic, the word to remember is given in italics .
Table 2-2. Cursor movement commands
Keystrokes |
Command name |
Action |
C-f |
forward-char |
Move forward one character (right). |
C-b |
backward-char |
Move backward one character (left). |
C-p |
previous-line |
Move to previous line (up). |
C-n |
next-line |
Move to next line (down). |
M-f |
forward-word |
Move one word forward . |
M-b |
backward-word |
Move one word backward . |
C-a |
beginning-of-line |
Move to beginning of line. |
C-e |
end-of-line |
Move to end of line. |
M-e |
forward-sentence |
Move forward one sentence. |
M-a |
backward-sentence |
Move backward one sentence. |
M-} |
forward-paragraph |
Move forward one paragraph. |
M-{ |
backward-paragraph |
Move backward one paragraph. |
C-v |
scroll-up |
Move forward one screen. |
M-v |
scroll-down |
Move backward one screen. |
C-x ] |
forward-page |
Move forward one page. |
C-x [ |
backward-page |
Move backward one page. |
M-< |
beginning-of-buffer |
Move to beginning of file. |
M-> |
end-of-buffer |
Move to end of file. |
( none ) |
goto-line |
Go to line n of file. |
( none ) |
goto-char |
Go to character n of file. |
C-l |
recenter |
Redraw screen with current line in the center. |
M- n |
digit-argument |
Repeat the next command n times. |
C-u n |
universal-argument |
Repeat the next command n times (four times if you omit n ). |
2.1.5 Emacs Commands and Your Keyboard
You can access many Emacs commands by pressing standard keys on your keyboard, such as PageDown(to scroll down one screen) or Home(to go to the beginning of a buffer). Figure 2-4shows a sample keyboard layout and what the keys do. Your keys may be in a slightly different place, but if you have a key with the same or a similar name, it should work. We say "should" because there are situations in which the keys won't work—for example, if you use Emacs on a remote machine. We recommend that you also learn the standard Emacs commands; they work on any keyboard, and they are often easier to reach once you learn them.
Figure 2-4. Emacs commands and your keyboard
Before you start practicing deletion commands, you might want to know the undo command, which is discussed fully later in this chapter. Typing C-_or C-x uundoes your last edit; typing undoagain undoes the edit before that one, and so on.
Читать дальше