Vim cheat sheet

Cursor movement

Tip Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines.

Insert mode - inserting/appending text

Editing

Marking text (visual mode)

Tip Instead of b or B one can also use ( or { respectively.

Visual commands

Registers

Tip Registers are being stored in ~/.viminfo, and will be loaded again on next restart of vim.
Tip Special registers:

0 - last yank
" - unnamed register, last delete or yank
% - current file name
# - alternate file name
* - clipboard contents (X11 primary)
+ - clipboard contents (X11 clipboard)
/ - last search pattern
: - last command-line
. - last inserted text
- - last small (less than a line) delete
= - expression register
_ - black hole register

Marks and positions

Tip To jump to a mark you can either use a backtick (`) or an apostrophe ('). Using an apostrophe jumps to the beginning (first non-blank) of the line holding the mark.

Macros

Cut and paste

Tip You can also use the following characters to specify the range:
e.g.

:.,$d - From the current line to the end of the file
:.,1d - From the current line to the beginning of the file
:10,1d - From the 10th line to the beginning of the file

Indent text

Exiting

Search and replace