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#,它们一起使编辑代码比以前更快更容易,但即使如此,我认为我可以享受根本不需要使用鼠标。

甚至连方向键都没有。


当前回答

只需学习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)下运行。

其他回答

恕我直言,学习新东西总是值得努力的。我建议你打印一张小抄单,强迫自己日复一日地使用它。

要快速学习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,这很快就成为了我的第二天性。现在我抱怨的是没有vim仿真或插件的IDE。我注意到esc键已经成为我在vim之外的敌人。

我确实在Visual Studio中找到了几个vi模拟器:

http://code.google.com/p/vim-visual-studio/

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.

就我个人而言,

我发现许多终端文本编辑器有时无能为力。我会花时间买一个吗?绝对的!我将继续学习一个IDE。当然,最终还是要看个人喜好。