As a programmer I spend a lot of hours at the keyboard and I've been doing it for the last 12 years, more or less. If there's something I've never gotten used to during all this time, it's these annoying and almost unconscious constant micro-interruptions I experience while coding, due to some of the most common code editing tasks. Things like a simple copy & paste from a different line (or even the same line), or moving 1 or 2 lines up or down from the current position require too much typing or involve the use of the arrow keys ...and it gets worse when I want to move further - I end up using the mouse. Now imagine this same scenario but on a laptop.
我一直在考虑学习VIM,但掌握它所需的时间总是让我想后退一步。
我想听听那些学会了它的人的意见,如果它最终成为你生活中不可或缺的东西之一。
在工作中,我使用VS2008, c#和r#,它们一起使编辑代码比以前更快更容易,但即使如此,我认为我可以享受根本不需要使用鼠标。
甚至连方向键都没有。
如果你是一个编辑大量文本的程序员,那么学习一个严肃的文本编辑器是很重要的。你学习哪种严肃文本编辑器并不是特别重要,它在很大程度上取决于你期望在其中编辑的环境类型。
原因是这些编辑器经过高度优化,可以执行您将经常执行的各种任务。例如,考虑在每行末尾添加相同的文本位。这在一个严肃的文本编辑器中是微不足道的,但在其他方面却非常麻烦。
通常vim的杀手特性被认为:A)它在你遇到的几乎所有Unix上都可用;B)你的手指很少需要离开主行,这意味着你可以非常非常快地编辑文本。即使在编辑巨大的文件时,它也通常非常快速和轻量级。
然而,还有很多替代方案。Emacs是最常见的例子,当然,如果你深入研究它,它不仅仅是一个高级文本编辑器。在使用vim/gvim多年后,我个人现在是一个非常满意的TextMate用户。
切换到其中任何一种的诀窍是强迫自己按照它们的意图使用它们。例如,在vim中,如果您手动执行一个多步骤过程中的每一步,或者如果您使用方向键或鼠标,那么可能有更好的方法来完成它。停下手头的工作去查一下。
如果不做其他事情,可以学习vim和Emacs的基本导航控件,因为它们会到处弹出。例如,你可以在Mac OS、大多数Unix shell、Eclipse等任何文本输入字段中使用emacs风格的控件。你可以在less(1)命令、Slashdot、gmail等中使用vim风格的控件。
玩得开心!
I'd say vim is definitely worth learning. I picked it up last summer, and it is now my editor of choice for just about everything (java is a stretch, but doable when I don't need extensive analysis support). As everyone has already affirmed, it is a wonderfully efficient tool.
For what it's worth, I only learned a fairly small subset of vim's features (which took a day or two) from a graphical tutorial, and a few odds and ends from here (long read), and the search and replace functionality, and I was hooked. I've learned things since then, but at my leisure. I'd say the learning curve flattens out at this point, but then, I was using it pretty heavily and was surrounded by others who were, too.
要快速学习vi(m),首先必须理解整个设计。
Vim有一组很棒的光标移动命令,检查一些(X是一个字符,#是一个数字):
J k进入箭头
0美元
w w b b
ctrolD crtolU
ctrolE ctrolY
H m l
fX fX tX tX,;
%
gg G
n n
mX 'X”
还有很多,要一一列举是很无聊的。其中许多工具都支持在命令之前添加计数,比如用4j向上移动4行。
现在,回到设计中,键入一个命令,如d,用于删除,然后移动光标,该命令应用于从光标位置到移动结束的文本段。例如,H移动到屏幕顶部,dH删除到屏幕顶部,cH更改(替换)到屏幕顶部。
这个设计很强大。它还可以减少或组织你需要学习的内容。
毫无疑问,第一步是学习一些光标移动命令。比如说,一开始是8到10个。那么你就差不多完成了。
Vim绝对值得学习,以下是部分总结前面所述的主要原因:
Vi/Vim can be found on most unix systems.
Vim allows you to easily code without taking your hands off the keyboard.
If you plan you configure anything in a unix based system likelihood is you going to be editing a fair few config files, therefore you'll want to learn a terminal based editor, of which vim is one of the best (sorry emacs).
Vim compiles/has precompiled binaries for almost every OS out there. No need to post "I need a textmate alternative for [insert OS]", you'll have Vim instead!
There are a lot of good plugins out there to add alot of functionality, such as in-editor cvs diffs, although some of these require a fair amount of tinkering.
另外,如果您喜欢Vim键绑定,也有一些ide在它们的编辑器中包含了Vim绑定,用于简单的命令,例如Komodo Edit。
要获得学习Vim的帮助,请尝试在终端中输入'vimtutor'并按照说明进行操作。还有一本书是特别好的Hacking Vim
I too put off learning vi or vim for many years. Matter of fact, I use to make fun of the "vi guys" who always seemed to be doing finger aerobics. Then, as I moved away from Windows and over to Linux as my primary OS, I had to become more familiar with vim. It was a learning curve and it still is. After 9 years of using vim on a daily basis I still find myself learning new and faster ways of doing things. What I use to think of as "finger aerobics" actually turned out to be an extremely efficient way of being productive. I can now do a whole lot more code development in a whole lot less time and effort than I ever did prior to vim. And as I'm sure you know vim runs on about every platform out there so you always have it when you need it. Also, if you like GUI's they have GUI versions for most platforms. Personally, just like the mouse, I don't want to see a menu bar, scroll bars, etc. cluttering up my editing window(s).
如果你决定尝试一下vim,我强烈推荐O'Reilly的《vi Editor Pocket Reference》一书。它很便宜,如果你只是学习vi (vim),它是很棒的。完整的vim书籍也很好,但口袋参考给你所有的基础知识,快速高效。
这绝对是值得努力的。
使用Vi(m)的人会告诉您一个明显的原因,还有两个原因人们似乎从来没有提到过。
这是一个显而易见的例子:
Vi无处不在,功能强大得令人难以置信,通过学习一次,您就可以在几乎任何有键盘的计算机上使用这种功能。
下面是学习Vim的一些鲜为人知的原因:
It's not half as much effort as you think it's going to be. Run through the Vim tutor once (vimtutor at a shell, or in Windows run it from the Vim folder in the Start Menu), and you'll already be well on your way to competence, and it's all downhill from there. I was up to the level where I could use Vim at work without taking any noticeable productivity hit within less than a week's worth of lunchtimes.
It's fun! Editing text is like a game to me now. I actively enjoy it--which is pretty ridiculous, when you think about it.
还有两个不学习Vim的好理由:
它会让人上瘾,你会发现自己希望在所有的计算中都能使用Vim命令,而每当不能使用时就会诅咒。幸运的是,至少在某些情况下,有一些方法可以绕过这个问题。
同样,它会让人上瘾,尽管您不会因为实际使用Vim而失去任何生产力,但您将浪费数小时搜索使您的Vim体验更好的好提示,并阅读Stack Overflow上的Vim标签。
只需学习16个键的含义,就可以从vim中获得良好的功能:ijkdbw9:q!%s/nNEsc。只需要i:wqEsc就可以完成基本的构造。
你需要知道的前两个键是:Esc将你带入命令模式(你开始的模式),i将你带入插入模式(正常输入)。
为了拯救你需要
退出打字模式(Esc)
键入冒号:
输入小写字母w然后回车
要保存并退出,你需要这样做
退出打字模式(Esc)
键入冒号:
键入小写wq然后回车
不保存并强制退出,你需要
退出打字模式(Esc)
键入冒号:
小写的q!然后输入
要了解更多信息,可以在命令行上运行vimtutor。这是一节中等长度、结构合理的课。
除了i和Esc:你可以复制或超越一些MS Word功能,只需要jkwbd3:%s/nN。
b带你回到一个单词(Ctrl+←)
w带你前进一个单词(Ctrl+→)
9w带你前进9个单词
db删除前面的单词(Ctrl+Backspace)
D3b删除前面三个单词
9j向下移动9行
输入将带你到单词“ornithopter”的下一个实例,然后n和n分别到“ornithopter”的下一个和前一个出现。
:%s/ confaded /dangfangled/输入每一个“confaded”替换为“dangfangled”(就像在Word中查找和替换all一样)
这些都应该在“命令”模式(Esc)下运行,而不是在插入模式(i)下运行。