Item 3: Prefer backward-kill-word over Backspace
使用 backward-kill-word (向后删一词)而不是 Backspace(向后删一字)
Emacs Wizards try to avoid hitting the backspace key, because it's just remote enough from home-row to be annoying. We make typing mistakes all the time, but if you type faster than about 50 wpm, it's more economical to kill the entire word and re-type it than to painstakingly backspace to your error.
emacs高手一般都尽量避免使用backspace键,因为它离手的基本方位太远了。如果你经常打错字,但是你的速度又很快,一分钟打50个词以上的话,把整个词删掉重打可比勤勤恳恳地用backspace倒删到你打错的地方再从一半打起要经济实惠得多。
Here's what you add to your .emacs file:
加入下面的几行到你的.emacs文件中:
(global-set-key "\C-w" 'backward-kill-word)
(global-set-key "\C-x\C-k" 'kill-region)
(global-set-key "\C-c\C-k" 'kill-region)
(global-set-key "\C-x\C-k" 'kill-region)
(global-set-key "\C-c\C-k" 'kill-region)
Note that because Ctrl-w was already bound to kill-region, a very important command, you need to re-bind something else to kill-region. I chose Ctrl-x Ctrl-k (and its sloppiness-forgiving companion, Ctrl-c Ctrl-k), primarily because that's the way they did it at my old company, which was filled with wise Emacs Wizards who taught me a lot of what I know. Rebinding Ctrl-x Ctrl-k means it's no longer available for edit-kbd-macro, but you'll use that infrequently enough that it's not something you'll miss having a shortcut for.
请注意ctrl-w已经有一个默认绑定kill-region了,这是个相当重要的命令,所以你得把它重新绑定到其它按键序列中去。我用的是Ctrl-x Ctrl-k(然后再加一个容错版的Ctrl-c Ctrl-k)。这样用主要是因为我在以前工作的公司,一个很牛X的emacs高手这么帮偶设的,现在我会的很多emacs技术都是当初这个高手教偶的。重绑定Ctrl-x Ctrl-k意味着你没有了edit-kbd-macro的快捷键,但是这个键你真的不会经常去用,所以不会觉得丢了什么东东的。
As an added benefit, many Unix command shells provide Emacs-like command-line editing keys, and Ctrl-w is usually the default binding for backward-kill-word. So your usage will be consistent in shells.
这样做还有一个额外的好处:很多Unix命令行shell都提供类似emacs的命令行编辑按键,而Ctrl-W一般都是backward-kill-word的默认绑定。这样的话,你的习惯就和很多shell一致了。
The faster you type, the more valuable this tip becomes. You'll gradually develop a "feel" for the fastest way to back up and correct various kinds of typing mistakes. In general, here's how my fingers decide these days:
你打字越快,这招就越升值。慢慢地你对如何最快更改各种打字错误会培养出一种最适合你自己的感觉。我的手感一般是这样的:
1. If I've mis-typed a character or two in a fairly long word, and my cursor is still located right after the typo, then I'll use the backspace key.
1.如果我打错一两个字符,而此时我的光标刚好就在错误的旁边,我就用backspace键。
2. If the typo is somewhere in the last 15 to 20 characters or so, then I'll usually backward-kill-word to kill backward over the typo, and re-type the words.
2.如果错误字符在光标前面15到20个字符左右的地方,那我一般就使用Ctrl-W直接杀回去,然后重新打出这些词来。
3. If the typo is further back than that, but still on the same line, I'll use Alt-B to skip the cursor back to the word with the typo, and Ctrl-b to move it within the word to get to the typo.
For mistakes further away, I'll use Fast Navigation to get there: Item 4 covers at least part of this technique.
对于比之更远的错误,我会使用快速导航来回到那个位置。条款4讲到一部分这个技术。
One thing you'll need to be very careful of if you use Ctrl-w for backward-kill-word: Ctrl-w is hardwired to kill the window in many Windows applications. Do not pass go, do not collect $200,and in browser windows, do not save the contents of your form fields. That means if you're typing out something into an HTML form field, and you accidentally make a typo and hit Ctrl-w, kapow! All
your work will be lost instantly for you by Good Ole Microsoft Windows. I know of no way to override this horrid behavior. If you know, please tell me.
使用ctrl-w绑定backward-kill-word时有件事情你可得小心了:Ctrl-w在很多windows程序中是强行绑定到“关闭窗口”这 一操作上的。这一动作没得后悔,在浏览器窗口中,它也不会保存你填写过的表单。也就是说,如果你正在为一个网页填写表单,然后你忽地想用ctrl-w来更 正一个错误,咔嘣!--完咧~在你那好用的OLE版M$ windows上,你的所有工作都白费了。目前我还不知道怎么覆盖掉这个可怕的行为,如果你知道怎么做,麻烦你考虑我一下。
浙公网安备 33010602011771号