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

effective emacs中文版[2]

Posted on 2011-07-15 16:22  雪庭  阅读(306)  评论(0)    收藏  举报

Item 2: Invoke M-x without the Alt key

条款2:不用Alt来调用M-x


Alt-x is one of the most frequently typed Emacs key combos, and it involves scrunching your left hand up. Anything you're going to do thousands of times should be streamlined, so you want to be able to start a M-x sequence with the Ctrl key (once you've completed Item 1!)
Alt-x是最常用的emacs组合键,每次使用时你都得把左手蜷起来。任何一个你要做几千次的动作最好应该是流线型的,所以你最好希望可以用Ctrl键来调用M-x。(要想用Ctrl舒服,你得选把条款1完成了)

There's another very important reason to get in the habit of using a Ctrl sequence: the Alt key is unreliable and nonstandard across platforms. In particular, when you're logged in to a remote host via telnet or ssh, Alt-x may or may not work, depending on the system type and the terminal configuration. Rather than mess with the headache of learning to configure every system you work
on to know about the Alt key, it's easier to use a key sequence that always works.
要养成使用Ctrl键习惯的另一个重要原因是:Alt键并不可靠也并不是跨平台的标准键(译注:好羡慕作者能接触那么多BT的机型啊)。尤其是当你通过telnet或者ssh远程序登录时,在一些系统的设置或者终端设置下,alt-x可能都不能使用。与其为不同的系统设置而头痛,还不如直接就不使用alt键,使用一个任何时候都有效的组合键相对来说更加容易且方便。

The key sequence I use is Ctrl-x Ctrl-m. Note that when you invoke a 2-key sequence with the same modifier key, you can just hold down the modifier key, then press the 2 keys. So with this key sequence, invoking M-x involves pressing and holding Ctrl, typing x, then typing m.To enable the Ctrl-x Ctrl-m sequence add the following lines to your .emacs file:

我选用的组合键序列是Ctrl-x Ctrl-m。请注意,当你调用一个2键序列,而这两个组合键都使用相同的转义键时,你只需按住转义键(这里指Ctrl),再按其它两个键即可(这里指x和m)。所以现在调用M-x的方法是:按住Ctrl,按x,按m,松开Ctrl。

将下面的lisp表达式加到你的.emacs文件中,就可以启用Ctrl-x Ctrl-m了:


(global-set-key "\C-x\C-m" 'execute-extended-command)
(global-set-key "\C-c\C-m" 
'execute-extended-command)

注: 我在使用过程中,发现\c-x\c-m与\c-x RET等价,有些命令需要\c-x RET处理,如

;; 选择的编码
C-x <RET> f coding <RET>
占用\c-x RET会导致无法设置编码,所以我是用的是:
(global-set-key "\C-c\C-m" 'execute-extended-command)
(global-set-key "\C-x\C-n" 'execute-extended-command)

 

I add the second line so that Ctrl-c Ctrl-m will also invoke it, which makes the key sequence even more forgiving. If I miss Ctrl-x and hit Ctrl-c accidentally, it still works. Neither of these key sequences is bound by default in Emacs, so you're not biffing any other useful shortcuts by doing this.

我另加了一行设定Ctrl-c Ctrl-m也调用同一命令,使得这个按键组合更能容错一些。如果偶不小心把Ctrl-x按成Ctrl-c,仍然能够成功调用。这两个按键都没有默认的emacs绑定,所以你的设置不会影响到其实的快捷键。

You should practice this key sequence until you get used to it, and then you'll almost never need to use Alt-x again. (You'll still use the Alt key for other commands, which I'll cover later.)
你应该把这个按键序列练到习惯为止,到时你差不多都不想再用alt-x了。(当然,你还会用到alt键来做其它的事,一会儿就告诉你)

Incidentally, if you want to fine-tune this tip to extraordinary levels, then you probably don't want to use your ring-finger for typing the x-key when you hit Ctrl-x. I use my left index finger,since I'm used to it that way, but you're probably better off using your left middle finger. The reason is that your hand isn't technically on home row when your left pinkie is jammed down on the
Caps-Lock key that you've turned into Ctrl. The point is to use whatever requires the least amount of stretching, followed by the least amount of finger motion. You should experiment until you find what's most comfortable for you.
顺便说一下,如果你想把这招发挥到极致,那在你按Ctrl-x最好不要用你的无名指来敲x键。这时我会用左手的食指的敲,因为觉得这样比较习惯,但是你可能会觉得用左手中指会更好一些。这是因为当你用小指去按那个变成Ctrl的Caps-Lock时,你的手并不处于键盘的基本方位。关键是要使用尽可能少的肢体伸缩,尽可能少的手指动作。你可以实验出你自己觉得最舒服的方式来。