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

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

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


当前回答

: % s /搜索/替换,

您可以使用除/(斜杠)以外的其他字符分隔模式以进行替换。这样就不必转义文件路径的斜杠。

其他回答

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

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.

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

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

^P和^N

完成上一个(^P)或下一个(^N)文本。

^O和^I

转到前一个(^O -“O”为旧)位置或下一个(^I -“I”靠近“O”)位置。

当您执行搜索、编辑文件等时,您可以通过这些“跳转”向前和向后导航。

标志着

按ma (m-标记,a -标记的名称)。稍后要返回位置,键入' a '。

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

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

进一步使用xcramps的建议,我无法告诉你我用了多少次:

: % !排序

对文件中的项列表进行排序。

细节:

:范围!命令

将在指定的行范围上执行shell命令。一个范围通常被指定为开始,结束

例子: 1,3指定前3行 'a,'b选择书签a和b之间的文本 ,$选择整个文档(。=第一线;$ =最后一行) %是.,$的快捷方式,还可以选择整个文档。

您可以随意混合和匹配数字、书签、.和$。