Cheat sheet for vim, a terminal based text editor.
Moving
keys / command | function |
---|
h | right |
j | up |
k | down |
l | left |
w | next word |
b | previous word |
W | next word space separated |
B | previous word space separated |
e | end of word |
0 | start of line |
$ | end of line |
^ | first character of line |
H | first line on screen |
M | line in middle of screen |
L | last line on screen |
:n <Number> | go to line number |
Ctrl + d | move down half page |
Ctrl + u | move up half page |
} | move down until next blank line |
{ | move up until next blank line |
gg | go to top of page |
G | got to bottom of page |
Files
keys / command | function |
---|
:e <Name> | open file |
:w | write changes |
:q | quit, wont work if not saved |
:q! | quit without saving |
:wq | write and quit |
:x | save and exit if changes have been made, just quits when nothing changed |
:wqa | save all and quit |
ZZ | write and quit |
ZQ | quit without saving |
Editing Text
keys / command | function |
---|
~ | change case of character |
> | indent right |
< | indent left |
c | cut out highlighted text |
y | yank highlighted text |
d | delete highlighted text |
yy | yank current line |
dd | delete and yank current line |
p | insert text after cursor |
P | insert text before cursor |
x | delete character under cursor |
X | delete character before cursor |
Insert and Overwrite Text
keys / command | function |
---|
i | enter insert mode, insert before cursor |
I | insert at start of line |
a | append after cursor |
A | append at end of line |
o | new line below |
O | new line above |
C | change rest of line |
r | overwrite single character |
R | insert mode but for replacing |
Search and replace
keys / command | function |
---|
/<pattern> | look for pattern forward |
?<pattern> | look for pattern backwards |
n | next match |
N | previous match |
:%s/<old>/<new>/gn | replace old with new |
:%s/<old>/<new>/gc | replace old with new, needs confirmation |
f <char> | move forward to next char |
F <char> | move back to char |
t <char> | move forward in front of char |
T <char> | move back before char |
Undo and Redo
keys / command | function |
---|
u | undo |
U | undo only current line |
Ctrl-r | redo |
Tabs
keys / command | function |
---|
:tab | make new tab |
gt | go to next tab |
gT | previous tab |
:vsp | vertically split |
Ctrl + ws | split horizontal |
Ctrl + wv | split vertical |
Ctrl + ww | switch window |
Ctrl + ww | quit window |
This list might be expanded