Vim Commands Cheat Sheet

Searchable cheat sheet of Vim commands — modes, motion, editing, search and files.

A searchable Vim commands cheat sheet — modes, motion, editing, search and replace, files and windows — with plain-English meanings. Runs entirely in your browser, nothing uploaded. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

How do I save and quit in Vim?

In Normal mode type :w to write (save), :q to quit, and :wq (or :x, or ZZ) to write and quit. Use :q! to quit without saving any changes.

Vim is a modal text editor: the same keys do different things depending on the mode you are in. That power is what makes Vim fast once learned and bewildering at first. This searchable cheat sheet collects the most-used commands — entering modes, moving around, editing, searching and replacing, and managing files and windows — each paired with a plain-English description so you can find the keystroke you need in seconds.

How it works

The reference is grouped into five sections that mirror how you actually work in Vim:

GroupCovers
Modesi, a, o, v, V, Ctrl-v, Esc
Motionh j k l, w b e, gg, G, 0, $
Editingx, dd, dw, d$, yy, p, u
Search & replace/pattern, n, N, :%s/old/new/g
Files & windows:w, :q, :wq, :q!, splits

Type a key or an action — for example delete, save, or search — into the search box and the list filters live to matching commands and descriptions.

Understanding Vim’s modal design

Vim has four primary modes, and switching between them efficiently is the key skill:

Normal mode is the default. You cannot type text directly here — instead, every key is a command. h, j, k, l move the cursor; d, y, c begin delete, yank, and change operations; : opens the command line. Press Esc at any time to return to Normal mode from anywhere else.

Insert mode is for typing text. Enter it with i (insert before cursor), a (append after cursor), o (open a new line below), or O (new line above). You type normally until you press Esc to return to Normal.

Visual mode is for selecting text. v selects character by character, V selects whole lines, Ctrl-v selects a rectangular block. Once selected, operators like d or y act on the selection.

Command-line mode opens when you press : in Normal mode. This is where you write, quit, search and replace, and run Ex commands. Press Enter to execute or Esc to cancel.

Essential commands in context

Saving and quitting

:w          write (save) the file
:q          quit (fails if unsaved changes exist)
:wq         write and quit
:x          write only if changed, then quit
ZZ          same as :x — write if changed and quit
:q!         quit without saving, discarding all changes
:wa         write all open buffers

Moving efficiently

h j k l     left / down / up / right (one character/line)
w           jump to start of next word
b           jump back to start of previous word
e           jump to end of current word
0           go to the first character of the line
^           go to the first non-whitespace character
$           go to the end of the line
gg          go to the first line of the file
G           go to the last line
42G         go to line 42
Ctrl-u      scroll half a page up
Ctrl-d      scroll half a page down
%           jump to the matching bracket / parenthesis

Editing text

x           delete the character under the cursor
dd          delete (cut) the current line
dw          delete to the start of the next word
d$          delete to the end of the line
D           same as d$ — delete to end of line
yy          yank (copy) the current line
yw          yank to the next word
p           paste after the cursor
P           paste before the cursor
u           undo the last change
Ctrl-r      redo (un-undo)
.           repeat the last change
r<char>     replace the character under the cursor with <char>
ciw         change inner word (delete word and enter Insert)
cit         change inner tag (useful for HTML/XML)

Search and replace

/pattern    search forward for pattern
?pattern    search backward for pattern
n           jump to the next match
N           jump to the previous match
*           search forward for the word under the cursor
:%s/old/new/g      replace all occurrences in the file
:%s/old/new/gc     replace all, confirm each
:5,15s/old/new/g   replace in lines 5 to 15 only

Windows and splits

:split      open a horizontal split
:vsplit     open a vertical split
Ctrl-w h/j/k/l  move between splits (left/down/up/right)
Ctrl-w w    cycle to the next split
:close      close the current split

Common pitfall: how to exit Vim

The most googled Vim question is how to quit. If you are stuck:

  1. Press Esc (multiple times if unsure) to ensure you are in Normal mode.
  2. Type :q! and press Enter to quit without saving.
  3. Alternatively, type :wq and Enter to save and quit.

Everything runs in your browser — this is a static reference and nothing is uploaded.