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

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

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


当前回答

从Vim中构建和调试代码!

配置

没什么,真的。您需要在当前目录中创建一个Makefile。

要编译

在Vim中,输入:make调用shell并构建程序。当输出滚动时,不要担心;当它完成时,只需按Enter键返回Vim。

神奇的

在Vim中,您可以使用以下命令:

:cl列出错误、警告和其他消息。 :cc在屏幕底部显示当前的错误/警告消息,并跳转到代码中的违规行。 :cc n跳转到第n条消息。 :cn进入下一条消息。 :cp跳转到上一条消息。

还有更多;如果你感兴趣,在Vim中输入:help:cc。

其他回答

:b[缓冲区名称的任何部分]来切换缓冲区。因此,如果你有两个缓冲区," someotherfile1 .txt"和"someotherfile2.txt",你可以切换到第二个,只需输入":b 2.t<enter>"。它还支持制表符补全,尽管这不是必需的。

说到制表符补全,设置:set wildmode=full wildmenu也非常有用。它为命令模式提供了完全的选项卡补全功能,在使用它时还提供了非常有用的ncurses风格菜单,其中包含所有可能的匹配。

我为我的一个朋友创建了我最常用的命令的参考:

select                                   v
select row(s)                            SHIFT + v
select blocks (columns)                  CTRL  + v
indent selected text                     >
unindent selected text                   <
list buffers                             :ls
open buffer                              :bN (N = buffer number)
print                                    :hardcopy
open a file                              :e /path/to/file.txt
                                         :e C:\Path\To\File.txt
sort selected rows                       :sort
search for word under cursor             *
open file under cursor                   gf
  (absolute path or relative)
format selected code                     =
select contents of entire file           ggVG
convert selected text to uppercase       U
convert selected text to lowercase       u
invert case of selected text             ~
convert tabs to spaces                   :retab
start recording a macro                  qX (X = key to assign macro to)
stop recording a macro                   q
playback macro                           @X (X = key macro was assigned to)
replay previously played macro *         @@
auto-complete a word you are typing **   CTRL + n
bookmark current place in file           mX (X = key to assign bookmark to)
jump to bookmark                         `X (X = key bookmark was assigned to
                                             ` = back tick/tilde key)
show all bookmarks                       :marks
delete a bookmark                        :delm X (X = key bookmark to delete)
delete all bookmarks                     :delm!
split screen horizontally                :split
split screen vertically                  :vsplit
navigating split screens                 CTRL + w + j = move down a screen
                                         CTRL + w + k = move up a screen
                                         CTRL + w + h = move left a screen
                                         CTRL + w + l = move right a screen
close all other split screens            :only

*  - As with other commands in vi, you can playback a macro any number of times.
     The following command would playback the macro assigned to the key `w' 100
     times: 100@w

** - Vim uses words that exist in your current buffer and any other buffer you may have open for auto-complete suggestions.

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

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

这句话总是让我高兴起来:

:help 42

vimcryption

vim -x文件。txt

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