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

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

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


当前回答

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

其他回答

我很惊讶没有人提到Vim的窗口支持。我几乎每次打开Vim都会使用Ctrl + W, S。

^X-F使用当前目录中的文件名完成。不再从终端复制/粘贴或痛苦的双重检查。

^X-P使用当前文件中的单词完成

:set scrollbind强制一个缓冲区与另一个缓冲区一起滚动。例如,把你的窗户分成两个垂直的窗格。在每个文件中加载一个文件(可能是同一文件的不同版本)。Do:设置每个scrollbind。现在,当你滚动其中一个窗格时,两个窗格将一起滚动。比较文件的理想选择。

我希望我能早点知道基本的视觉块模式。即使你不使用Vim做其他的事情,在Vim中打开一个文件仅仅是为了一些块操作也可以节省大量的时间。我很确定我在手动做这种事情上浪费了大量的时间。

我发现一些特别有用的例子,比如始终如一地重构符号常量名列表:

进入可视块模式(我在Windows上用Ctrl + Q代替Ctrl + V)

移动光标以突出显示所需的块。

然后,我无论文本和按Esc有文本插入前面的块上的每一行。

使用A而不是I将文本插入到每行的块之后。

此外,简单地用~切换视觉选择的大小写可以节省大量时间。

还有简单地删除列,当然是用d。

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

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.

我的Vim脑库中最近添加的一些内容:

^wi:通过分割窗口跳转到光标下的标签。 cib/ cib:分别更改当前括号()或大括号{}集合内的文本。 :set listchars=tab:>-,trail:_ list:显示不同于其他空格的制表符/尾随空格。它对Python编码有很大帮助。