我一直在Vim中学习新的命令,但我相信每个人都偶尔会学习一些新东西。我最近才知道:

Zz, zt, zb -位置光标在中间,顶部或底部的屏幕

还有什么其他有用或优雅的命令是你希望很久以前就学会的?


当前回答

cw

更改单词-删除光标下的单词,并将您置于插入模式下键入一个新的单词。当然,这也适用于其他移动键,所以你可以做c$之类的事情来改变到行尾。

F +字符

查找当前行上字符的下一个出现位置。因此,您可以使用vft来选择当前行上下一个“t”之前的所有文本。这是另一个移动键,所以它也适用于其他命令。

其他回答

Q <字母> -记录一个宏。

and

@<相同字母> -回放。

这些是到目前为止在Vim中最有用的命令,因为你可以让计算机为你做很多工作,你甚至不需要写一个程序或任何东西。

^r^w以命令模式将单词粘贴到光标下。

它在使用grep或replace命令时非常有用。

直到[character] (t)。它适用于任何接受范围的命令。我最喜欢的是ct;或ct),它会删除尾随分号/右括号之前的所有内容,然后将您置于插入模式。

另外,G和gg也很有用(分别转到底部和顶部)。

Don't press Esc ever. See this answer to learn why. As mentioned above, Ctrl + C is a better alternative. I strongly suggest mapping your Caps Lock key to escape. If you're editing a Ctags compatible language, using a tags file and :ta, Ctrl + ], etc. is a great way to navigate the code, even across multiple files. Also, Ctrl + N and Ctrl + P completion using the tags file is a great way to cut down on keystrokes. If you're editing a line that is wrapped because it's wider than your buffer, you can move up/down using gk and gj. Try to focus on effective use of the motion commands before you learn bad habits. Things like using 'dt' or 'd3w' instead of pressing x a bunch of times. Basically, any time that you find yourself pressing the same key repeatedly, there's probably a better/faster/more concise way of accomplishing the same thing.

在我们的软件商店中,变量声明需要排序。在我们使用的语言中,多个变量可以出现在同一行上。

new var1,var2,var3,etc

这是一个真正的痛苦,通过和视觉上尝试排序每个变量。在Vim中,块突出显示和排序命令是我的朋友:

将光标移动到要排序的第一个变量。 发出v命令进入可视模式。 将光标移动到最后一个要排序的变量的末尾(在我的例子中,我输入$到行末尾)。 执行!sort命令告诉Vim对突出显示的文本进行排序。

只有在底层系统上存在'sort'命令时,这才会起作用。