敏捷之道——提高命令行编辑速度
2011-03-31 星期四 晴朗
经常在shell命令行下操作,如果能够节省一点时间,由于操作频繁,总的节约时间还是挺可观的。
shell命令行默认的编辑模式是emacs编辑模式。所以其实可以方便的是使用emacs的快捷键来提高工作效率。当然,你也可以配置成VI编辑模式,不过我觉得Emacs的几个快捷键挺好记的,我都已经习惯了,呵呵。
废话少说,直切正题。由于时间关系,我这里就直接贴了,耐心看,其实英文没有什么的。
说明:C表示Ctrl,M在我的Ubuntu下是Alt-Shift。
1. Motion and Objects
Characters
C-f
forward-char
. Moves forward (to the right) over a character.
C-b
backward-char
. Moves backward (to the left) over a character.
The f for forward and b for backward mnemonic will reoccur.
Words
M-f
forward-word
. Moves forward over a word.
M-b
backward-word
. Moves backward over a word.
Note the f/b mnemonic. Also, as another mnemonic, note that M-f is like a "bigger" version of C-f.
Lines (vertically)
C-n
next-line
. Moves down to the next line.
C-p
previous-line
. Moves up to the previous line.
When moving by lines, the cursor tries to stay in the same column, but if the new line is too short, it will be at the end of the line instead. This is very important: Emacs doesn't insert spaces at the ends of lines (end of line is unambiguous).
说明:c-n和c-p可以在shell的history中一条条翻转,相当于向上向下箭头。
Lines (horizontally)
C-a
beginning-of-line
. Moves to the beginning of the current line.
C-e
end-of-line
. Moves to the end of the current line.
e for end, a for the beginning of the alphabet.
这个命令我用的最多了,也特别好记。
2. Deleting, Killing and Yanking
Emacs' deletion commands are also based on the textual objects above. But first, a terminological distinction: Deletion means to remove text from the buffer without saving it; most deletion commands operate on small amounts of text. Killing means to save the removed text, so that it can be yanked back later someplace else.
Killed text is saved on the kill ring. The kill ring holds the last N kills, where N is 30 by default, but you can change it to anything you like by changing the value of the variable kill-ring-max. The kill ring acts like a fifo when you're killing things (after the 30th kill, kill number one is gone), but like a ring when you're yanking things back (you can yank around the ring circularly). kill-ring-maxdoesn't apply to the amount of text (in bytes) that can be saved in the kill ring (there's no limit), only to the number of distinct kills.
Characters
C-d
delete-char
. Deletes the character to the right of (under, if the cursor is a block that covers a character) the cursor.
DEL
delete-backward-char
. Deletes the character to the left of the cursor.
Remember, Emacs does not use C-h (aka Backspace) for deletion, but for help! Depending on your cultural background, this may well be the single hardest thing to learn about Emacs. Why does Emacs make this choice? Well, since there's no need for two commands to delete one character backward, and since DEL (aka Delete) can only be mnemonic for deletion while C-h is a nice mnemonic for help, the choice was made. Me, I've never used C-h to delete, so it suits me fine.
说明:DEL是指backspace键
Words
M-d
kill-word
. Kills to the end of the word to the right of the cursor (forward).
M-DEL
backward-kill-word
. Kills to the beginning of the word to the left of the cursor (backward).
Lines (horizontally)
C-k
kill-line
. Kills to the end of the current line, not including the newline. Thus, if you're at the beginning of a line it takes two C-k's to kill the whole line and close up the whitespace.
C-u
kill-line
. Kills to the beginning of the current line, not including the newline.
这两个命令基本是我最常用的了。
3. Infinite Undo with Redo
One of the most important Emacs commands is undo
, invoked with C-_ (control underbar). C-_ is a valid ASCII character, but some keyboards don't generate it, so you can also use C-x u -- but it's more awkward to type, since it's a two-character command.
The undo command allows you to undo your editing, back in time. It's handy when you accidentally convert all of a huge file to uppercase, say, or delete a huge amount of text. One keystroke changes everything back to normal.
We say Emacs has infinite undo because, unlike some editors, you can undo a long chain of commands, not just one previous one, even undoing through saves. We say Emacs has redo because you can reverse direction while undoing, thereby undoing the undo.
Once you get used to this feature you'll laugh at any editor that doesn't have it (unless you're forced to use it...). It's very important to get comfortable with undo as soon as possible; I recommend reading the undo section of the manual carefully and practising.
4. Searching and Replacing
Emacs has a variety of unusual and extremely powerful search and replace commands. The most important one is called incremental search. This is what the command isearch-forward
, bound to C-s, does: it searches incrementally, one character at a time, as you type the search string. This means that Emacs can often find what you're looking for before you have to type the whole thing. To stop searching, you can either hit RET or type any other Emacs command (which will both stop the search and execute the command). You can search for the next match at any point by typing another C-s at any point; you can reverse the search by typing C-r; and you can use DEL to delete and change what you're searching for.
isearch-backward
, bound to C-r, works the same way, but searches backward. (Use C-r to search for the next match and C-s to reverse the search.)
Occasionally you may want to search non-incrementally (though I rarely do). You can do this by typing C-s RET text RET, where text is the text to search for.
Much more useful is word search, which lets you search for a sequence of one or more words, regardless of how they're separated (e.g, by any number and combination of newlines and whitespace). To invoke word search, type C-s RET C-w word word word RET.
Emacs can also search incrementally (or not) by regular expressions; this is an extremely powerful feature, but too complex to describe here.
这个命令实际上是特别好用的命令,当然对于很常见的比较长的命令,我们还是建立一个alias比较合适,但是对于你在本session中经常敲打的命令,C-r是非常好用的。C-s貌似不行。
另外,IPython使用跟shell一样的快捷键,当然,确切的说,是跟Emacs一样的快捷键。
EOF.
分享到:
相关推荐
《Web开发敏捷之道——应用Rails进行敏捷Web开发,第2版》书籍配套代码(zip) 资源很少的哦
敏捷软件开发——中国史
敏捷与高效——手机应用程序开发模式研究 敏捷与高效——手机应用程序开发模式研究 一本很好的书,如果有志从事这一行,值得拥有
敏捷软件开发——原则、模式与实践 第二部分
敏捷领导力——培养与提升团队凝聚力.pdf
Web开发敏捷之道(英文版)——应用Rails进行敏捷Web开发(原书第4版)
敏捷软件开发——原则、模式与实践,扫描完整版。
敏捷项目管理的12条石蕊测试题,要成为敏捷的一员,你需要有能力去问:“这是敏捷吗?”如果你曾经质疑过某个特定流程、实践、工具或方法是否遵守敏捷宣言或12原则,请参考以下问题。
Web开发敏捷之道——应用Ralls进行敏捷Web开发.pdf 全书主要分为两大部分。在“构建应用程序”部分中,读者将看到一个完整的“在线购书网站”示例。在随后的“Rails框架”部分中,作者深入介绍了Rails框架的各个组件...
论文研究-敏捷决策体系——基于Internet和虚拟组织的网络化决策支持体系.pdf, 在高速动态变化的企业生存环境条件下 ,为了实现快速而准确的决策 ,提出了一种基于 ...
《敏捷软件开发——原则、模式与实践》很经典的书,值得一看。有条件的话建议买本书。
《敏捷软件开发——原则、模式与实践》很经典的书,值得一看。有条件的话建议买本书。
声明:文中提到的模型不是我们发明的。Spotify,和其他优秀的敏捷型公司一样,处于高速地发展中。这篇文章只是我们当前工作方式的缩影。我们的敏捷旅程仍在进行中,
敏捷开发(Agile Development)是一种面临迅速变化的需求快速开发软件的能力。为了获取这种敏捷性,我们需要使用一些可以提供必要的纪律和反馈的实践。
web 开发敏捷 之道 pdf 带书签高清web 开发敏捷 之道 pdf 带书签高清web 开发敏捷 之道 pdf 带书签高清web 开发敏捷 之道 pdf 带书签高清
金蝶零售行业解决方案,以帮助客户成功为宗旨,结合金蝶软件和原商祺软件对零售业业务多年的深入研究和积累,在金蝶ERP管理软件的统一平台上,通过强大的店面运营管理,...增强对市场的反应速度,提高企业核心竞争力。