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

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

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


当前回答

选项卡式界面

除了分开的窗口,您还可以有选项卡窗口。在转义模式下,输入tabnew。您可以像这样打开多个选项卡。要在选项卡之间导航,输入tabn。这将移动到下一个选项卡。要移动到选项卡窗口,键入tabn2以移动第二个选项卡,依此类推。

要关闭制表符,输入tabc、tabclose或直接关闭。

如果你在终端模拟器(基本上是GUI中的终端)中,那么你可以尝试执行set mouse=a。完成后,您可以用鼠标在编辑器内单击。这也将帮助您通过单击在选项卡之间导航,并通过单击右侧的关闭按钮关闭。

对齐您的代码-完整的文件

只需在转义模式下输入G=gg。

折叠代码

假设您有一个完成的函数。您希望最小化(或折叠)这部分代码,以便可以释放一些空间并减少混乱。只需选择代码。然后输入折叠。

这将折叠代码。如果您想展开代码,只需转到那里,并键入zo。要再次折叠,输入zc。

其他回答

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

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

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

^y将复制光标上方的字符。

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.

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

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