Vim Commands Reference
Every essential Vim command with its mode context (normal / insert / visual / command), variations with counts, real examples, and the mode-confusion gotcha that traps everyone. Vim 8+ default bindings.
Navigation
h j k l
The four fundamental cursor keys in Vim: h moves left, j down, k up, l right. Reach for them any time you would instinctively hit an arrow key — keeping your hands on the home row is the whole point.
w / b / e
Word motions: w jumps to the start of the next word, b to the start of the previous word, e to the end of the current/next word. These are the fastest way to hop across a line without leaving the home row.
0 / $
0 jumps to the very first column of the line; $ jumps to the last character. Use ^ (bonus) if you want the first non-blank character instead of column zero.
gg / G
gg jumps to the first line of the file; G jumps to the last line. Prefix G with a number to jump to that absolute line — the fastest way to reach a specific line from a stack trace.
%
In normal mode, % jumps between matching pairs of (), [], {}, and (with matchit) HTML/XML tags. Indispensable for navigating nested code and confirming that a stray brace really does close where you think it does.
Ctrl-D / Ctrl-U
Ctrl-D scrolls the view (and cursor) half a screen down; Ctrl-U scrolls half a screen up. Faster than jkjk when skimming a long file, and the cursor stays in a predictable place on screen.
Editing
i / a / o / O
The four ways to enter insert mode: i inserts BEFORE the cursor, a inserts AFTER it, o opens a new line BELOW and enters insert mode, O opens a new line ABOVE. Choosing the right one saves a motion or two before you start typing.
dd
Deletes the current line (and stores it in the unnamed register, so you can paste it back with p). The bread-and-butter 'get rid of this line' command.
yy
'Yank' (copy) the current line into the unnamed register — Vim's word for copy. Combine with p/P to duplicate lines without touching your system clipboard.
p / P
Paste the contents of the unnamed register: p pastes AFTER the cursor (or below the line, for a linewise yank), P pastes BEFORE the cursor (or above the line). Works with anything you dd'd, yy'd, or x'd.
u / Ctrl-R
u undoes the last change; Ctrl-R redoes it. Vim has a full undo TREE (see :undolist and g-/g+) but for day-to-day work these two keys are enough.
x
Deletes the character under the cursor — Vim's equivalent of the Delete key. It's a cut, so the character lands in the unnamed register.
r / R
r replaces the single character under the cursor with the next key you press — no need to enter insert mode. Capital R enters REPLACE mode, where every character you type overwrites the one under the cursor until Escape.
.
Repeats the last CHANGE (any command that modified the buffer, including the whole insert-mode session that followed it). The single most-loved Vim feature — learn to structure edits so that '.' does the work for the next N occurrences.
Selection (Visual)
Search & Substitute
/ and ?
/ searches forward for a regex, ? searches backward. After the search, press n to jump to the next match and N for the previous — searching is a first-class motion, so d/foo deletes up to the next 'foo'.
n / N
n jumps to the next match of the last search, N to the previous. Direction is relative to the ORIGINAL search direction — if you searched with ?, then n goes backward.
* / #
* searches forward for the whole word under the cursor; # searches backward. Zero typing needed — put your cursor on the identifier and hit *.
:s and :%s
Substitute (find-and-replace) within a range of lines. Without a range :s works on the current line only; :%s uses % as shorthand for the whole file (equivalent to :1,$s). Add flags like g (all matches per line) and c (confirm).
Files & Save
:w / :saveas
Write (save) the current buffer to disk. Without an argument :w saves to the current file; with an argument it writes a copy without switching buffers. Use :saveas when you want to rename the buffer to the new file and keep editing that one.
:q / :q!
:q closes the current window (or exits Vim if it's the last one); :q! quits and DISCARDS unsaved changes. If you're the 'how do I exit Vim' meme — this is the answer.
:wq / ZZ
Write the buffer to disk and quit the window. ZZ (normal mode, two capital Zs) does the same thing without leaving the keyboard's home row — with the subtle difference that ZZ only writes if the buffer actually changed.
:e
Edit (open) a file in the current window. With no argument, :e reloads the current file from disk — handy after external changes.
Windows, Splits & Tabs
:vsplit / :split / :tabnew
:split (or :sp) opens a horizontal split, :vsplit (:vsp) a vertical split, :tabnew a new tab page. All three optionally take a filename to open in the new pane/tab.
Ctrl-W
Ctrl-W is the prefix for every window-management command. Follow it with h/j/k/l to move between splits, with =/_/| to resize, or with c/o to close windows.
Modes
Macros & Shell
q / @
q{register} starts recording a macro into that register; press q again to stop. Play it back with @{register}, and repeat the last macro with @@. Macros are just recorded keystrokes — anything you can do by hand, you can automate.
:!
:! runs a shell command and shows its output; with a range, :[range]!cmd pipes those lines through cmd and REPLACES them with its output. The bridge from Vim to the rest of your Unix toolbox.