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

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

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


当前回答

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

其他回答

Qx将开始记录击键。你几乎可以做任何编辑任务,Vim都记得。当你完成时再次点击q,然后按@x来重放你的击键。这对于过于复杂而无法编写映射的重复编辑非常有用。可以使用x以外的字符进行多次记录。

对于强制Vim配置,请查看https://github.com/jmcantrell/dotfiles-vim

使用选项卡打开多个文件

:tabe filepath

在打开的文件之间导航

gt and gT or :tabn and :tabp

保存打开的会话,以便稍后可以返回打开的文件列表

:mksession session_file_name.vim

打开已创建的会话

vim -S session_file_name.vim

立即关闭所有文件

:qa

这是我最近学到的另一个命令

autocmd

它允许你在一个事件上运行命令,所以你可以在保存文件时使用如下命令:

:autocmd BufWritePost *.cpp :make

vimcryption

vim -x文件。txt

您将被要求输入密码,编辑并保存。现在,无论何时在vi中再次打开该文件,都必须输入密码才能查看。

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.