This custom VIM reference chart is organized for me – but you can borrow it. There are lots of quick VIM reference charts, but this one is mine. It has the stuff I’m always looking for and none of the crap I don’t need.
VIM quick reference cheat sheet (from ViEmu.com)
David’s frequently used & forgotten VIM commands
Command | What it does |
j, k, h, l, b, e | up, down, left, right, beginning of word, end of word |
x | delete current character |
cw | change current word and insert |
i, o | insert at current character, insert new line |
r, R | replace current character only, Replace many characters |
u, Ctrl + r | undo, redo |
a, A | append to right of character and insert, Append to end of line and insert |
dd | delete line (deleted line goes to clipboard) |
ma, d’a/y’a | mark text area and delete or yank it (goes to clipboard) |
yy | yank line |
p | paste |
:set nu, syn on/off | turn on line numbers, turn on/off syntax highlighting |
:88 | goto line 88 |
/pattern, n, N | search for term, find next, find previous |
gg, G | start of document, end of document |
%s/stuff/toreplace/g | find and replace all, (s/…/…/ finds/replaces on current line only) |
J | joins the current line with the next one |
% | on (, ), [, ], { or }, % goes matching opening or closing bracket |
vi -r file | open file in recovery mode to recover unsaved changes |
v, V, Ctrl+v | highlight text, highlight line, exit visual mode |
Ctrl+f, Ctrl+b | page up, page down |
:set backup writebackup | Create a backup when editing files |
:set backupdir=$VIMbkup | Place backups in …bkup |
:set directory=$VIMtmp | Place swap files in …tmp |
:%s!^!<add this text>! | Will prepend <add this text> to every line in the document |
:'<,’>s!^!<add this text>! | Will prepend <add this text> to every SELECTED line in the document |