我一直在Vim中学习新的命令,但我相信每个人都偶尔会学习一些新东西。我最近才知道:
Zz, zt, zb -位置光标在中间,顶部或底部的屏幕
还有什么其他有用或优雅的命令是你希望很久以前就学会的?
我一直在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.
其他回答
当光标位于引号、圆括号、括号或大括号上时,按%查找匹配项。
vimcryption
vim -x文件。txt
您将被要求输入密码,编辑并保存。现在,无论何时在vi中再次打开该文件,都必须输入密码才能查看。
ma
move cursor down
:'a,.!program
这将获取从您设置的a标记(ma)到当前行(.)之间的所有文本,通过程序运行它,并用结果替换标记区域的内容。您甚至可以使用它来查看目录的内容(例如),通过创建一个空行,然后将光标放在该行上,
:.!ls
哦,你可以像这样为a-z(即ma)设置标记,以及
'a
会跳到你标记为"a "的位置
/向前搜索,和?重复向后搜索,而不需要补充搜索模式。
Groovy的东西。Vi被严重低估了。一旦你掌握了它的窍门,你就再也不想使用IDE提供的编辑器了。
:x #(Save and Quit a File)
与:wq或ZZ相同
直到[character] (t)。它适用于任何接受范围的命令。我最喜欢的是ct;或ct),它会删除尾随分号/右括号之前的所有内容,然后将您置于插入模式。
另外,G和gg也很有用(分别转到底部和顶部)。