查询命令

在normal模式下按下 / 即可进入查找模式,输入要查找的字符串并按下回车。

Vim会跳转到第一个匹配。

按下 n 查找下一个,按下 N 查找上一个。

Vim查找支持正则表达式,例如 /vim$ 匹配行尾的 “vim” 。

保存

Esc + :

Linux Vim

Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient.

vim

Title: Vim Mode Edit Mode->Common Mode: ESC Common Mode-> Edit Mode: <i | o | a> Common Mode-> Command Mode: <: | ? | /> Command Mode-> Common Mode: Enter

Cursor Move

Command Desc
H Head line start
M Middle line start
L Bottom line start
G Last Line
nG n Line
gg First Line(1G)
n space → n
n enter ↓ n

Vim Set

Command Desc
:set nu show line num
:set nonu hide line num

Find & Replace

Command Desc
/word find word after cursor
?word find word before cursor
n continue search before
N continue search & REVERSE direction
:n1,n2s/word1/word2/g replace word1 with word2 in [n1,n2] lines
:1,$s/word1/word2/g replace word1 with word2 in [First,Last] lines
:1,$s/word1/word2/gc replace word1 with word2 in [First,Last] lines, need CONFIRM

Delete & Copy

  • n stands for n times
Command Desc
[n]x,X x(del), X(backspace)
[n]dd delete cursor line, [n] cursor ↓ n lines delete
d[H M L G nG] delete form cursor line and target
d[0 $] [0] delete form cursor to line head, [$] to line end
[n]yy copy cursor line, [n] cursor ↓ n lines copy
y[H M L G nG] same as delete
y[0 $] same as delete
P paste copy content at cursor’s NEXT line
p paste copy content at cursor’s PREV line
u undo
. redo

参考资料

查看端口占用