博客园  :: 首页  :: 联系 :: 管理

effective emacs中文版[4]

Posted on 2011-08-15 14:07  雪庭  阅读(212)  评论(0)    收藏  举报

Item 4: Use incremental search for Navigation

条款4:使用递增式搜索来进行快速导航

 

Moving the cursor around efficiently is one of the keys to becoming an Emacs Wizard. IDE users spend most of their time fumbling around with the mouse. They wouldn't dream of doing it any other way, but they don't realize how inefficient their motions are. In the hands of a Master, Emacs becomes the most powerful and efficient text-editing tool on the planet, in large part because it allows you to do almost everything without using the mouse.

知道如何高效地移动光标是成为emacs高手的关键。IDE用户把他们大部份的时间花在摸索鼠标上了,根本没有想过如何用其它方法来实现光标导航,却不知道自己的方法是多么的低效。在一个高手的手中,emacs是世界上最高效的文本编辑工具,主要是因为她可以让你不用鼠标做到几乎所有的事情。

Emacs Wizards always have their Emacs sessions as tall as possible, filling the screen vertically,because vertical screen space is such a premium when you're viewing a document. When you can view a fair number of lines of text on screen at once, using incremental search is often much faster than any other way of precisely positioning the cursor.

emacs高手总是设法让他们的会话窗口越高越好,最好是能垂直地填满整个屏幕--因为垂直的屏幕空间在你查看一个文档时可以说是最宝贵的空间了。当你使用屏幕空间一次性查看多行文本时,使用递增式搜索一般比使用鼠标直接定位要快得多。

Get in the habit of using Ctrl-r (isearch-backward) and Ctrl-s (isearch-forward) for moving around in the document. Whenever you need to jump the cursor backward or forward more than about 5 lines,and you can see the target location, you should be using i-search.

 

养成使用ctrl-r(向前递增式搜索)和ctrl-s(向后递增式搜索)来在文档中进行移动的习惯。当你要向前或者向后移动5行左右,而且你又看得到移动的目的地时,你应该使用递增式搜索。

To do it effectively, you don't necessarily need to search for the exact word where you want to put the cursor. Let your eye defocus slightly and take in the whole paragraph or region around the target point, and choose a word that looks reasonably unique or easy to type. Then i-search for it to navigate to it. You may need to hit Ctrl-r or Ctrl-s repeatedly if your anchor word turns out not to be unique. But Emacs will highlight all the matches, so if there are more than a couple of
them, Ctrl-g out of the search and choose another anchor word.

要想高效地做到这一点,你并不需要搜索你光标目的地处的整个单词。让你的目光掠过目标点周围的一行或者一段话,选择一个看起来唯一性比较强而且比较好敲的单词,然后递增地搜过去。如果你选单词不是那么的唯一,那可能要按两三次crtl-r或者ctrl-s。但是放心,emacs会把已匹配的单词高亮显示,如果你看到匹配的东东太多了,按一下ctrl-g,然后重找一个词来递增导航。

It's difficult to overemphasize how powerful this technique is, once you've mastered it. Mastering it simply requires that you do it repeatedly until your fingers do it "automatically". Emacs eventually becomes like an extension of your body, and you'll be performing hundreds of different keystrokes and mini-techniques like this one without thinking about them. It's comparable to the hundreds of subtle techniques you acquire for driving a car well.

一旦你掌握了它,再怎么强调这一招数的强大都不会过份的。你必须不断地重复直到你的手“自动地”去这样按才能算是真正掌握这一招。这时,emacs就好像 变成你身体的延伸一样,成为你身体的一部分,你可以想都不用想就把这些微妙的按键敲出来。这类似于你学车时最终掌握的一些微妙的本能反应。