分类: LINUX
2010-10-05 18:44:31
移动光标
The easiest way to move the cursor is to click the left button on your mouse or
to press the arrow keys. However, it's a hassle to reach for a mouse all the
time. Learn to use keyboard commands to move around so that you will ultimately
achieve blinding speed and maximum productivity in Emacs.
移动光标最方便的方法就是点击鼠标左键或者按箭头儿键。然而,每次都去够鼠标比较麻烦。学会用按键移动光标,你会在Emacs里获得盲打的速度以及最高的效率。
To use Emacs commands to move the cursor forward one space, type C-f (f for
"forward"). As you might guess, C-b moves the cursor backward. To
move up, type C-p (for previous-line), and to move down, type C-n (for
next-line). It's easier to memorize commands if you remember what the letters
stand for.
用Emacs指令让光标向前移动一个位置,输入C-f(f表示'向前').你可能猜到了,C-b向后移动一个位置.向上移动,输入C-p(表示前一行),向下移动,输入C-n(下一行).如果你理解字母的含义,你就很容易记住这些指令.
Figure 2-2 illustrates how to move up, down, left, and right using Emacs
commands.
图2-2 说明如何使用Emcas指令上下左右移动光标.

Figure 2-2. Basic cursor motion
图2-2.基本光标移动
If you're at the end of a line, C-f moves to the first character on the next
line. Likewise, if you're at the beginning of a line, C-b moves to the last
character of the previous line. If there's no place to go, Emacs beeps and
displays the message Beginning of buffer or End of buffer.
如果在行尾,按C-f会移动到下一行的首个字符.同样,如果在行首,C-b会移动到前一行的最后一个字符.如果没有地方可以移动,Emacs会鸣叫一声并显示信息'Beginning of buffer'或者'End of buffer'.
2.1.1 Other Ways to Move the Cursor
2.1.1其他移动光标的方法
Now we'll learn some more advanced ways to move the cursor. One common way is
moving forward and backward by word: M-f moves forward a word; M-b moves
backward a word. You can also move to the beginning or end of the line. C-a
moves you to the beginning of the line (just like a is the beginning of the
alphabet). C-e moves you to the end of the line. To move backward one sentence,
type M-a; to move forward one sentence, type M-e. To move forward a whole
paragraph at a time, type M-}; to move backward a paragraph, type M-{. If
you're in the middle of a sentence or paragraph, moving back a sentence or
paragraph actually takes you to the beginning of the current sentence or
paragraph.
现在介绍一些更高级的移动光标的方法.一个常见的方法是按单词向前向后移动:M-f向前移动一个单词;M-b向后移动一个单词.也可以移动到行首行尾.C-a移动到行首(正如a是字母表的首字母).C-e移动到行尾.向回移动一句话,按M-a,向前移动一句话按M-e.向前一移动一段,按M-};向回移动一段按M-{.如果光标在句子或段落中间,那么向回移动一句或一段,实际上是移动到当前句子或段落的开头.
Figure 2-3 uses a few paragraphs of Victor Hugo's Les Misérables to show how
you can move the cursor more than one character at a time.
图2-3 用Victor Hugo的Les MisMisérables中的几段来演示如何每次移动光标位置不止一个字符.

Figure 2-3. Moving the cursor more than one character at a time
图2-3.移动光标位置不止一个字符.
You may have picked up on a pattern here. Notice the difference between
commands starting with Ctrl and those starting with Meta. Ctrl commands
generally move in smaller units than their associated Meta commands. For
example, C-b moves the cursor backward one character, whereas M-b moves the
cursor back one word. Likewise, C-a moves to the beginning of the line, whereas
M-a moves to the beginning of a sentence.
或许你已经领会到一个规律。注意到以Ctrl开头和以Meta开头的指令间的区别。Ctrl指令与对应的Meta指令相比一般移动更小的单元。例如:C-b光标移动一个字符,而M-b光标移动一个单词。同样,C-a移动到行首,而M-a移动到句首。
There's one caveat about moving by sentence or paragraph. Emacs defines a
sentence pretty strictly. You need two spaces after the final punctuation mark,
unless you're at the end of the line. If there's only one space, Emacs won't
recognize it. Similarly, moving backward and forward by paragraph involves
understanding the Emacs definition of a paragraph. To Emacs (and to most of
us), paragraphs are either indented with a tab or at least one space or have
blank lines between them (block style). You can change these definitions, but
first you have to understand how to use regular expressions, which are
discussed briefly in Chapter 3 and in more depth in Chapter 11. Chapter 10 discusses
how to change variables.
按行或段移动时有一个忠告.Emacs对句子的定义相当严格。除非光标在行的末尾,否则必须在最后的标点符号后有两个空格。Emacs不识别末尾仅有一个空格的句子。同样,向前向回移动一段包括理解Emacs对段落的定义。对Emacs而言(同样对我们大部分人而言),段落不是用个Tab缩进就是至少有个空格开始,或者段落之间有空白行(块风格)。你可以改变这些定义,但是首先你要理解如何使用正则表达式,在第三章有简单介绍,第11章有更深入的讲解。第10章讨论如何修改变量。
If your file has page breaks in it, you can move to the next page or previous
page by typing C-x ] (forward-page) or C-x [ (backward-page). Similar to
paragraph and sentence movement, moving by page involves the Emacs definition
of what a page is. A variable called page-delimiter defines what constitutes a
page break. If there are no Emacs-recognized page breaks in the file, Emacs
regards the buffer as one very long page. In this case, the forward-page
command takes you to the end of the buffer, and the backward-page command takes
you to the beginning of the buffer.
如果文件中有分页符,可以按'C-x
]'移动到下一页,按'C-x ['移动到前一页.与段落和句子的移动类似,按页移动包含着Emacs对页的定义.名为page-delimiter的变量定义了哪些东东构成分页符。如果没有Emacs可以识别的分页符,Emacs就认为整个缓冲区就是一个非常长的页面。这种情况下,下翻页指令会移动到缓冲区的尾部,上翻页指令会移动到头部。
In text mode, a page break is a formfeed character that tells the printer to
move to the next page (to feed the next form or page through the printer, hence
the term formfeed) before continuing to print. If you are in text mode and you
want to insert page breaks in your file, type C-q C-l (the lowercase letter L).
C-q is the quoted-insert command. It tells Emacs to put a C-l control character
in your file, rather than interpreting C-l as the recenter command. A C-l
character looks like two characters (^L), but it's really only one. (Try to
erase one using Del and see what we mean.)
文本模式下,分页符是一个进纸标识,告诉打印机移动到下一页(通过打印机移动到下一页面,进纸符由此而来),然后继续打印。如果在文本模式下向文件中插入分页符,输入'C-q C-l'(小写字母L).C-q是引用插入指令,它告诉Emacs插入一个C-l控制符到文件中,而不是解释C-l是一个重定位指令。一个C-l字符看起来像两个字符(^L),但实际上只是一个字符。(试着用Del键删除一个,就知道是不是一个字符了。)
2.1.2 Moving a Screen (or More) at a Time
2.1.2 一次滚动一屏(或更多)
Like other graphical applications, you can use the scrollbar to move around in
Emacs. Like most things in Emacs, in addition to using the mouse or scrollbar
to move around, you should learn Emacs's own keyboard commands to maximize your
productivity.
像其他图形应用程序一样,你可以使用滚动条在Emacs中移动。像Emcas中大部分东西一样,除了用鼠标和滚动条之外,还应该学习Emacs自己的快捷键来最大化你的工作效率。
If you want to page through a file one screen at a time, use the PgDown key or
type C-v. Emacs displays the next full screen from your file. It leaves a
couple of lines from the previous screen at the top to give you a sense of
context. Likewise, pressing M-v (or the PgUp key) shows you the previous
screen. Together, M-v and C-v provide a convenient way to scroll through a file
quickly.
如果你想一次移动一屏,使用PgDownq键或者输入C-v。Emacs会显示下一整页。它会在上部保留前一页的几行文字,让你想起前文内容。同样,按M-v(或PgUp键)显示上一页。M-v和C-v提供了一个快速滚动的方式。
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.
当你输入任何移动指令,移动到当前显示内容之外的位置时,Emacs都会自动滚屏。例如:当前光标在显示内容的最后一行,然后按C-n,Emacs向下滚动。同样,如果在显示内容的最上一行,按C-p会滚动到上一页。
You often want to move all the way to the beginning or the end of a file. Type
M-> or press End to 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.
你经常会想从任意位置移动到开头或结尾。输入M->或者End移动到缓冲区尾。输入M-<或Home移动到缓冲区头。>指向结束位置,<指向开始位置,这或许有助于你记住这两个指令。
There are two more ways to move around that may come in handy. M-x goto-line
Enter n Enter moves 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
Enter goes to the nth character of the file, counting from the beginning. In
both cases, n is a number.
还有两个移动的方式也能派上用场。‘M-x goto-line Enter n Enter’ 移动光标到第n行。当然,Emacs是从文件开头计算行数的。同样‘M-x goto-char Enter n
Enter’移动到从文件开头计算的第n个字符。这两种情况下,n表示一个数字。
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 9 for details).
对于程序员来说,这些指令是很有用的,因为很多编译器给出错误消息:Syntax error on line 356.(第356行语法错误)。使用这些指令你可以很容易的到达错误的位置。还有一些更复杂的方式可以将Emacs与编译器或其他程序的错误信息关联上。此外,还有其他光标移动指令只适用于编程(见第9章详细介绍)。