Vim常用命令速记表

Vim、Emacs配置和使用
回复
neil.sun
帖子: 110
注册时间: 2009-08-28 15:00

Vim常用命令速记表

#1

帖子 neil.sun » 2010-08-24 13:09

当初学vim的时候自己写的,共享下,希望对别人也有用。

代码: 全选

basic:
            ↑
←   h   j   k   l   →
        ↓

:w              write / save
:w {file}       write to file / save as
:wq / ZZ        write and quit / save and quit
:q! / ZQ        force quit / quit without saving

d{motion}       delete / cut
y{motion}       yank / copy
p               put / paste

cursor -> line:
a               append after the cursor
A               append after the line
i               insert before the cursor
I               insert before the line
r               replace at the cursor
R               replace the line
s               substitute at the cursor
S               substitute the line
u               undo            CTRL-R      undo the undo
U               undo the line
v               start visual mode per character
V               start visual mode line-wise

forward -> backward:
x               delete characters forward
X               delete characters backward
p               put after the cursor
P               put before the cursor
o               open a line below
O               open a line above

f{char}         find {char} forward
F{char}         find {char} backward
t{char}         till {char} forward
T{char}         till {char} backward
;               next {char} occurrence
,               previous {char} occurrence

/{pattern}      search {pattern} forward
?{pattern}      search {pattern} backward
n               next {pattern} occurrence
N               previous {pattern} occurrence

motion / word -> WORD:
w               forward to the start of word
W               forward to the start of WORD
e               forward to the end of word
E               forward to the end of WORD
b               backward to the start of word
B               backward to the start of WORD
ge              backward to the end of word
gE              backward to the end of WORD

0               to the first character of the line
^               to the first non-blank character of the line
$               to the last character of the line
g_              to the last non-blank character of the line

d -> dd -> D:
d{motion}       delete
dd              delete a line
D               delete to the end of the line
c{motion}       change
cc              change a line
C               change to the end of the line
y{motion}       yank/copy
yy              yank/copy a line
Y               same as yy, unfortunately we are not in a perfect world

advanced:
H               High / to first line on the window
M               Middle / to middle line of the window
L               Low / to last line on the window

:1 / gg         to first line of the file
:[+/-]{number}  to relative/absolute line number
:$ / G          to last line of the file

%               find a matching

:s/old/new      substitute once
:s/old/new/g    substitute all on a line
:%s/old/new/g   substitute all in the file
:%s/old/new/gi  substitute all in the file, ignore case
:%s/old/new/gn  count occurrence only, do not substitute
:%s/old/new/gc  substitute all in the file, with confirmation

:!{cmd}         execute {cmd} with the shell
:!!             repeat last shell command

:w !sudo tee %  save as root

tnsw
帖子: 9
注册时间: 2008-12-07 18:21

Re: Vim常用命令速记表

#2

帖子 tnsw » 2010-08-24 13:29

感谢,对我这个初学者很有帮助
liuwang
帖子: 5
注册时间: 2010-08-30 13:43

Re: Vim常用命令速记表

#3

帖子 liuwang » 2010-10-05 12:27

非常感谢 :em11
asiabaa
帖子: 79
注册时间: 2007-10-09 15:40
系统: Ubuntu 12.04
来自: 广东-广州
联系:

Re: Vim常用命令速记表

#4

帖子 asiabaa » 2011-12-17 11:12

收藏!
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: Vim常用命令速记表

#5

帖子 eexpress » 2011-12-17 20:14

应该看
附件
vi-vim-cheat-sheet-中文.png
● 鸣学
回复