Skip to content
shellhacks.dev

Vim Cheat Sheet

A searchable Vim cheat sheet: modes, saving and quitting, motions, editing with operators and text objects, search and replace, visual mode, macros and splits.

Free · No sign-up · Your inputs stay in your browser

Reference

Vim cheat sheet

KeysDoes
i a oInsert before cursor, after it, on a new line below
EscBack to normal mode
:w :q :wq :q!Save, quit, save and quit, quit without saving
:x or ZZSave if changed and quit
h j k lLeft, down, up, right
w b eNext word, previous word, end of word
0 ^ $Line start, first non-blank, line end
gg G 42GFirst line, last line, line 42
Ctrl-d Ctrl-uHalf page down, up
%Jump to the matching bracket
dd yy p PDelete line, copy line, paste after, paste before
dw d$ diw di"Delete word, to end of line, inner word, inside quotes
ciw ci( citChange inner word, inside parentheses, inside a tag
x rDelete character, replace character
u Ctrl-rUndo, redo
.Repeat the last change
v V Ctrl-vVisual by character, by line, block
>> <<Indent, unindent
/text n NSearch forward, next, previous
* #Search the word under the cursor
:%s/old/new/gcReplace in the whole file, asking each time
:nohClear search highlighting
:set numberLine numbers (:set nu!)
:set pastePaste without auto-indent (not needed in Vim 8+ with bracketed paste)
qa ... q @aRecord a macro in register a, then play it
10@aPlay it ten times
:e fileOpen a file
:sp :vsSplit horizontally, vertically
Ctrl-w wMove between splits
:w !sudo tee %Save a file you opened without sudo (Vim only; Neovim needs a plugin)
:r !commandInsert a command's output
gg=GRe-indent the whole file
Ctrl-v j j I# EscComment out lines with a block insert

Normal-mode keys unless they start with a colon. Commands compose: an operator (d, c, y), an optional count and a motion (w, $, iw, it), so d3w deletes three words. The same keys work in Neovim and in the Vim modes of VS Code and JetBrains IDEs.

The grammar of Vim

Vim commands compose: an operator (d delete, c change, y copy), an optional count and a motion or text object (w word, $ end of line, iw inner word, i( inside parentheses). Once that clicks, d3w, ci" and yap need no memorising. Vim's built-in :help and the vimtutor command are the best teachers; the online Vim help mirrors them.

On servers

vi or vim is on almost every server, so a few commands go a long way: editing a config over SSH, fixing a crontab, resolving a merge conflict. Neovim and editor Vim modes accept the same keys.

Share

Frequently asked questions

How do I exit Vim?
Press Esc, then type :q and Enter to quit, :wq to save and quit, or :q! to quit without saving.
How do I search and replace in Vim?
:%s/old/new/g replaces in the whole file; add c (/gc) to confirm each one.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Go deeper

Suggested reading

Keep planning

Similar tools