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

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

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


当前回答

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.

其他回答

我经常创建用于编辑任务的函数,并将它们存储在.vimrc文件中,这样我就可以再次找到它们。

例如,读取已转换为单行的.NET调用栈:

function! FixCallStacks()
:%s;\[NLN\];\r;g
:%s;\[TAB\];\t;g
endfunction

ZZ(工作方式:wq)

关于光标的位置:我发现光标总是停留在屏幕中间是很酷的

set scrolloff=9999

您可以使用一整套命令来更改括号/圆括号/引号/标记内的文本。这对于避免寻找群组的起点和终点非常有用。试试ci(, ci{, ci<, ci", ci', ct这取决于你想要改变的对象类型。而ca(, ca{,…变体也会删除括号/引号。

容易记住:change inside a bracasted statement /更改一个括号内语句。

^X-F使用当前目录中的文件名完成。不再从终端复制/粘贴或痛苦的双重检查。

^X-P使用当前文件中的单词完成

:set scrollbind强制一个缓冲区与另一个缓冲区一起滚动。例如,把你的窗户分成两个垂直的窗格。在每个文件中加载一个文件(可能是同一文件的不同版本)。Do:设置每个scrollbind。现在,当你滚动其中一个窗格时,两个窗格将一起滚动。比较文件的理想选择。

我真的希望我知道你可以使用Ctrl+C而不是Esc来切换插入模式。这对我来说是一个真正的生产力提升。