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

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

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


当前回答

星号键*将搜索光标下的单词。

[+Tab将带您到光标下的C函数的定义。(不过,这种方法并不总是有效。)

其他回答

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

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

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

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

在Bash的命令行上使用Vim绑定:

    set -o vi

在其他使用readline的程序中,按Ctrl + Alt + J从Emacs绑定切换到Vim绑定。

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.

:x #(Save and Quit a File)

与:wq或ZZ相同