Vim Cheat Sheet
Operator/Command | Function |
---|---|
d | Delete operator |
c | Change operator |
y | Yank (Copy) operator |
"*y | Yank operator to clipboard |
p | Put register after cursor |
P | Put register before cursor |
"*p | Put clipboard after cursor |
r | Replace one character |
. | Repeat a change |
n | Repeat a pattern |
N | Repeat a pattern backwards |
d (vis) | Delete selection (in visual mode) |
y (vis) | Yank selection (in visual mode) |
o (vis) | Move to other side of selection (in visual mode) |
Mode | Function |
---|---|
i | Enter Insert-mode at current position |
I | Enter Insert-mode at the start of the line |
A | Enter Insert-mode at the end of the line (Append) |
o | Enter Insert-mode at a new line beneath cursor |
O | Enter Insert-mode at a new line above cursor |
v | Enter Visual mode |
V | Enter Visual Line mode |
CTRL-V | Enter Visual Block mode |
R | Enter Replace mode |
Movement | Function |
---|---|
w | Next word |
e | Last character of next word |
2w | Next two words |
b | Previous word (back) |
ge | Last character of previous word |
G | Last line of file |
gg | Beginning of file |
NNG | Go to line number NN |
$ | End of line |
f | Find a character |
F | Find a character backwards |
% | Find a matching {},(),[] |
NxM Examples | Function |
---|---|
c$ / C | Change until end of line |
cl / s | Change one character |
cc / S | Change the whole line |
cf | Change until Find command |
dw | Delete word |
d2w | Delete two words |
dd | Delete a whole line |
dl / x | Delete character under cursor |
dh / X | Delete character left of cursor |
d$ / D | Delete until end of line |
df | Delete until Find command |
yw | Yank word |
y2w | Yank two words |
yy / Y | Yank a whole line |
y$ | Yank until end of line |
Text Object | Function |
---|---|
aw | A word |
as | A sentence |
ap | A paragraph |
a[ / a] | A [] block |
a( / a) | A () block |
a> / a< | A <> block |
at | A tag ("<tag></tag>") |
a{ / a} | A {} block |
a" / a' | A quoted string |
Fold Command | Function |
---|---|
zfap | Fold a paragraph |
zf% | Fold with % movement |
zfNNG | Fold to line NN |
zm | Fold more (one level) |
zr | Fold reduce (one level) |
zM | Fold More and More (all levels) |
zR | Fold Reduce and Reduce (all levels) |
zn | Disable folds temporarily |
zN | Re-enable folds |
zi | Toggle enable/disable |
zo | Open fold at cursor |
zc | Close fold at cursor |
zO | Open all folds at cursor |
zC | Close all folds at cursor |
zj | Move to the start of the next fold |
zk | Move to the end of the previous fold |
:mkview | Save all manual folds |
:mkload | Restore manual folds |
:folddo | Execute a command on folds |
Fold Flag | Function |
---|---|
set foldmethod=indent | Automatically folds by indentation ('shiftwidth' ). |
set foldmethod=syntax | Folds as defined by the syntax item |
set foldmethod=marker | Folds by markers in the text |
set foldmethod=expr | Folds by the expression defined in foldexpr |
set foldlevel=X | Go to a specific fold level (zm and zr increase/reduce) |