Cheet says: Everyone gets stuck in Vim at least once!
How to Exit (The #1 Question!)
:q Quit (if no changes)
:q! Quit without saving
:wq Save and quit
:x Save and quit (same as :wq)
ZZ Save and quit (no colon needed)
ZQ Quit without saving (no colon needed)
Modes
i Insert mode (before cursor)
a Insert mode (after cursor)
o Insert mode (new line below)
O Insert mode (new line above)
Esc Back to normal mode
v Visual mode (select text)
V Visual line mode
Ctrl+v Visual block mode
: Command mode
Navigation
h j k l Left, down, up, right
w Next word
b Previous word
0 Start of line
$ End of line
gg Start of file
G End of file
:42 Go to line 42
Ctrl+d Page down
Ctrl+u Page up
Editing
x Delete character
dd Delete line
dw Delete word
d$ Delete to end of line
yy Copy (yank) line
yw Copy word
p Paste after
P Paste before
u Undo
Ctrl+r Redo
. Repeat last command
Search & Replace
/pattern Search forward
?pattern Search backward
n Next match
N Previous match
* Search word under cursor
:%s/old/new/g Replace all in file
:s/old/new/g Replace all in line
:%s/old/new/gc Replace with confirmation
Visual Mode Operations
v Start selecting
y Copy selection
d Delete selection
> Indent
< Unindent
Useful Commands
:w Save
:e filename Open file
:split Horizontal split
:vsplit Vertical split
Ctrl+w w Switch windows
:set number Show line numbers
:set nonumber Hide line numbers
:set paste Paste mode (preserves formatting)
:noh Clear search highlight
Config (~/.vimrc basics)
set number " Line numbers
set relativenumber " Relative line numbers
set tabstop=4 " Tab = 4 spaces
set shiftwidth=4 " Indent = 4 spaces
set expandtab " Tabs to spaces
set autoindent " Auto indent
set mouse=a " Enable mouse
syntax on " Syntax highlighting
Pro Tips
ciw Change inner word
ci" Change inside quotes
di( Delete inside parentheses
=G Auto-indent to end of file
:%y+ Copy entire file to clipboard
:r !date Insert command output
:earlier 5m Go back 5 minutes
:later 5m Go forward 5 minutes
Help!
:help Open help
:help keyword Help on keyword
:q Close help
Remember: When in doubt, press Esc!