A quick reference for Vim โ the terminal text editor. Bookmark this page.
Modes
Normal mode โ default, press Esc to return
Insert mode โ press i, a, o, O to enter
Visual mode โ press v (char), V (line), Ctrl+v (block)
Command mode โ press : from Normal modeNavigation
h j k l โ left, down, up, right
w / b โ next/previous word
0 / $ โ start/end of line
gg / G โ start/end of file
:42 โ go to line 42
Ctrl+d/u โ half page down/up
Ctrl+f/b โ full page down/up
% โ matching bracketEditing
i โ insert before cursor
a โ insert after cursor
o / O โ new line below/above
x โ delete character
dd โ delete line
dw โ delete word
D โ delete to end of line
cc โ change (delete) entire line
cw โ change word
C โ change to end of line
r โ replace single character
u โ undo
Ctrl+r โ redo
. โ repeat last commandCopy and Paste
yy โ copy (yank) line
yw โ copy word
y$ โ copy to end of line
p / P โ paste after/before cursor
dd then p โ cut and paste (move line)
"ay โ yank into register a
"ap โ paste from register aSearch and Replace
/pattern โ search forward
?pattern โ search backward
n / N โ next/previous match
* โ search word under cursor
:s/old/new/ โ replace first on current line
:s/old/new/g โ replace all on current line
:%s/old/new/g โ replace all in file
:%s/old/new/gc โ replace all with confirmationVisual Mode
v โ character selection
V โ line selection
Ctrl+v โ block (column) selection
d โ delete selection
y โ yank selection
> / < โ indent/unindent selectionWindows and Tabs
:split file โ horizontal split
:vsplit file โ vertical split
Ctrl+w w โ switch between splits
Ctrl+w h/j/k/l โ navigate splits
:tabnew file โ new tab
gt / gT โ next/previous tab
:q โ close current split/tabFile Operations
:w โ save
:w file.txt โ save as
:q โ quit
:q! โ quit without saving
:wq or ZZ โ save and quit
:e file.txt โ open file
:e! โ reload file (discard changes)Advanced
ci" โ change inside quotes
ci( โ change inside parentheses
di{ โ delete inside braces
da" โ delete around quotes (including quotes)
=G โ auto-indent entire file (from cursor)
gg=G โ auto-indent whole file
:set number โ show line numbers
:set paste โ paste mode (no auto-indent)
:noh โ clear search highlightingTips and Tricks
- Use
vimtutorto learn interactively (30 min tutorial) - Use
.vimrcfor persistent configuration - Combine counts with commands:
5dddeletes 5 lines - Use macros:
qato record,qto stop,@ato replay - Use
:!commandto run shell commands from Vim