The Modes

A small finite state machine you carry in your head

Keys: Esc, Ctrl-[, Ctrl-C, i, v, V, Ctrl-V, R, :, Ctrl-O

Normal, insert, visual, replace, command-line, operator-pending, terminal. What each is for and how to move between them.

Vim has seven modes. You will spend essentially all your time in two of them โ€” normal and insert. The other five matter for specific jobs. Knowing they exist, and how the transitions work, is more important than memorizing every command in each.

Mode Status line What it's for
normal (empty) The default. Keys are commands.
insert -- INSERT -- Keys type text.
visual -- VISUAL -- -- V-LINE -- -- V-BLOCK -- Select text, then act on it.
replace -- REPLACE -- Overtype existing characters.
command-line shows typed : / / / ? Run an Ex command or search.
operator-pending (empty, but last key was an operator) Waiting for a motion or text object.
terminal -- TERMINAL -- An interactive shell inside Vim.

Getting Out

From any mode except normal mode, Esc returns to normal mode. From insert and visual mode, Ctrl-[ does the same. Build the Esc reflex: after every thought, escape.

Terminal mode is the exception โ€” Esc is forwarded to the shell. Use Ctrl-\Ctrl-N to escape from a Vim terminal.


Operator-pending: the secret seventh mode

When you press an operator like d, c, y, or >, Vim enters operator-pending mode and waits for a motion or text object. You're in normal mode no longer โ€” keys do different things in this state. i no longer enters insert mode; it begins a text object (inner ...). a no longer appends; it begins around-text-objects. The operator and motion together form a single change, which is what . repeats.

Operator d โ†’ operator-pending โ†’ text object iw โ†’ execute
KeyNote
d
i
w

The State Machine

Vim's seven modes and the transitions between them. *Normal mode* is the hub: every other mode is one keystroke away, and {key:Esc} always returns. *Visual mode* has three sub-modes โ€” char, line, block โ€” switched between by pressing {key:v} / {key:V} / {key:Ctrl-V} again while already in *visual mode*. *Terminal mode* is the one place where {key:Esc} doesn't actually escape: use {key:Ctrl-\}{key:Ctrl-N}.
Vim's seven modes and the transitions between them. Normal mode is the hub: every other mode is one keystroke away, and Esc always returns. Visual mode has three sub-modes โ€” char, line, block โ€” switched between by pressing v / V / Ctrl-V again while already in visual mode. Terminal mode is the one place where Esc doesn't actually escape: use Ctrl-\Ctrl-N.

Why this matters

When something surprises you in Vim โ€” a key doesn't do what you expected โ€” nine times out of ten you misjudged the current mode. "I pressed dd and it just typed two ds" โ†’ you were in insert mode. "I pressed i and a word disappeared" โ†’ you were in operator-pending mode after d. The fix is always the same: press Esc (twice when a completion popup is visible โ€” the first press dismisses the popup, the second exits insert mode) and start over from normal mode.

Worked example โ€” normal mode โ†’ insert mode โ†’ normal mode

The mode transition every editing change goes through.

Step 1 ยท Normal mode. Cursor on the space.
*Normal mode.* Cursor on the space.

When you open a file, you start in normal mode. Keystrokes are commands.

Step 2 ยท i,vim ยท i, then type , vim โ€” insert mode, text added.
{key:i}, then type `, vim` โ€” *insert mode,* text added.

i enters insert mode at the cursor; subsequent keys produce text. The status line below advertises the mode.

Step 3 ยท Esc ยท Esc โ€” back to normal mode.
{key:Esc} โ€” back to *normal mode.*

Esc commits the insert and returns to normal mode. The whole insertion is one undoable change.

Watch

See also: Modal Editing, The Universal Grammar, The Three Visual Modes, Replace Mode, One-Shot Normal Mode