简单的VIM命令,你希望你早些时候知道
我一直在学习VIM中的新命令,但我相信每个人都会偶尔学到新的东西。 我最近才了解到这一点:
zz,zt,zb - 将光标定位在屏幕的中间,顶部或底部
你希望你在几年前学过的其他有用或优雅的命令是什么?
我真的希望我知道你可以使用CtrlC而不是Esc来切换插入模式。 这对我来说是一个真正的生产力提升。
我学到的最近的“哇”技巧是一种复杂的搜索和替换方法。 通常在过去,我有一个非常复杂的正则表达式来进行替换,并且它不起作用。 有一个更好的方法:
: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
这里的“诀窍”(用于更好的单词)是您可以使用搜索创建正则表达式(以及“incsearch”在输入字符时突出显示它的方式),然后在替换中使用空模式:空模式默认为最后的搜索模式。
例:
/blue(d+)
:%s//red1/
相当于:
:%s/blue(d+)/red1/
看到:
:help 'incsearch'
:help :substitute
我为我的一位朋友创建了这个最常用命令的参考。 希望人们会发现有用的东西:
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:PathToFile.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.
链接地址: http://www.djcxy.com/p/49463.html
上一篇: Simple VIM commands you wish you'd known earlier
下一篇: In Vim how do I effectively insert the same characters across multiple lines?