insert
i | insert text before the cursor |
I | insert text before first non-blank |
a | append text after the cursor |
A | append text at the end of line |
o | insert text at a new line below current line |
O | insert text at a new line above current line |
copy
:[range]co[py] {address} | e.g. copy line 10-15 to line 20 (means append to current 20 line) :10,15 copy 20 more: help copy |
delete
r | replace a single character |
R | keep replacing character until [esc] is hit |
[N]s | delete [N] characters and insert text |
[N]S | delete [N] lines and insert text(same as 'cc') |
[N]dd or d[N]d | delete [N] lines |
[N]D | delete the characters under the cursor until the end of the line and [N-1] more lines |
[N]cc | delete [N] lines and insert text(same as 'S') |
[N]cw | delete [N] words(word does not include white space) and insert text |
c$ | delete to the end of line and insert text |
:[range]d[elete] [x] | e.g. delete lines 10 to 15: :10,15 delete more: help delete |
show information
Ctrl+g | display current filename and total line number |
Cursor movement
h - move left
j - move down
k - move up
l - move right
[N]| - jump to the Nth character of line
w - jump by start of Word (punctuation considered words)
W - jump by WORD (spaces separate words)
e - jump to End of word (punctuation considered words)
ge - Go to End of previous word (punctuation considered words)
E - jump to End of WORD (no punctuation)
gE - Go to End of previous WORD (no punctuation)
b - jump Backward by word (punctuation considered words)
B - jump Backward by WORD (no punctuation)
0 - (zero) start of line
^ - first non-blank character of line
g_ - Go to last non-blank character of line
$ - end of line
H - jump to the first line of current screen(H: Head)
M - jump to the middle line of current screen(M:middle)
L - jump to the last line of current screen(L:Last)
[N]G - go to the [N] line of file(or ':N'), so, '1g' go to the first line(or ':0')
G - Go to the last line of file(or ':$')
gj - Go to the next visual line
gk - Go to the previous visual line
g^ - Go to the first non-blank character of current visual line
g$ - Go to the end of current visual line
gm - Go to the middle of current visual line
Screen movement
CTRL-F - next page(F: Forward)
CTRL-B - previous page(B: Backward)
CTRL-U - previous half-page(U: Up)
CTRL-D - next half-page(D: Down)
CTRL-Y - screen up with one line step
CTRL-E - screen down with one line step
zz - move current line to the middle of the screen
zt - move current line to the top of the screen
zb - move current line to the bottom of the screen
Edit
u - Undo changes
U - Undo all latest changes on one line
J - join line below to the current one
. - repeat last change
xp - transpose two letters (delete and paste, technically)
CTRL-R - Redo changes which were undone
substitution
(enter ':help subs' for more details)
:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]
range
(enter ':help range' for more details)
% | the entire file, equal to 1,$ |
flags
(enter ':help flags' for more details)
c | confirm before substitution |
g | all occurrences in the line |
i | ignore case for the pattern |
I | don't ignore case for the pattern |
n | report the number of matches, do not actually substitute |
substitution example
将countbits全文替换为bitcount:
:%s/countbits/bitcount/g
将单词our全文替换为ours(ourself中的our不在替换范围之内):
:%s/\<our\>/ours/g