我一直在Vim中学习新的命令,但我相信每个人都偶尔会学习一些新东西。我最近才知道:
Zz, zt, zb -位置光标在中间,顶部或底部的屏幕
还有什么其他有用或优雅的命令是你希望很久以前就学会的?
我一直在Vim中学习新的命令,但我相信每个人都偶尔会学习一些新东西。我最近才知道:
Zz, zt, zb -位置光标在中间,顶部或底部的屏幕
还有什么其他有用或优雅的命令是你希望很久以前就学会的?
当前回答
ZZ(工作方式:wq)
关于光标的位置:我发现光标总是停留在屏幕中间是很酷的
set scrolloff=9999
其他回答
在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.
我最近学到的令人惊叹的技巧是一种进行复杂搜索和替换的方法。在过去,我经常有一个非常复杂的regexp来进行替换,但它不起作用。有一个更好的方法:
:set incsearch " I have this in .vimrc
/my complicated regexp " Highlighted as you enter characters
:%s//replace with this/ " You don't have to type it again
这里的“技巧”(找不到更好的词)是使用搜索来创建regexp(在输入字符时'incsearch'突出显示它),然后在替换中使用空模式:空模式默认为最后一个搜索模式。
例子:
/blue\(\d\+\)
:%s//red\1/
等价于:
:%s/blue\(\d\+\)/red\1/
See:
:help 'incsearch'
:help :substitute
直到[character] (t)。它适用于任何接受范围的命令。我最喜欢的是ct;或ct),它会删除尾随分号/右括号之前的所有内容,然后将您置于插入模式。
另外,G和gg也很有用(分别转到底部和顶部)。
从Vim中构建和调试代码!
配置
没什么,真的。您需要在当前目录中创建一个Makefile。
要编译
在Vim中,输入:make调用shell并构建程序。当输出滚动时,不要担心;当它完成时,只需按Enter键返回Vim。
神奇的
在Vim中,您可以使用以下命令:
:cl列出错误、警告和其他消息。 :cc在屏幕底部显示当前的错误/警告消息,并跳转到代码中的违规行。 :cc n跳转到第n条消息。 :cn进入下一条消息。 :cp跳转到上一条消息。
还有更多;如果你感兴趣,在Vim中输入:help:cc。