Overview

Vim’s learning curve is real but front-loaded. Once the modal model clicks, editing speed compounds. This card covers the motions, operators, and commands worth internalizing. For terminal multiplexing alongside Vim, see tmux-commands.

Modes

Every keystroke’s meaning depends on the current mode.

ModeHow to enterPurpose
NormalEsc or Ctrl-[Navigate and operate. The default mode.
Inserti, a, o, I, A, OType text.
Visualv (char), V (line), Ctrl-v (block)Select text for an operation.
Command:Enter ex commands (save, quit, substitute).
ReplaceROverwrite characters in place.

Return to Normal with Esc from any mode. When confused, press Esc twice.

Motions

Motions move the cursor. Prefix with a count: 3w moves three words forward.

MotionWhat it does
h j k lLeft, down, up, right.
w / WForward one word / WORD (whitespace-delimited).
b / BBack one word / WORD.
e / EForward to end of word / WORD.
0Start of line.
^First non-blank character of line.
$End of line.
ggFirst line of file.
GLast line of file.
{ / }Previous / next empty line (paragraph).
%Jump to matching bracket, paren, or brace.
f{c} / F{c}Jump to next / previous occurrence of character c on the line.
t{c} / T{c}Jump to just before / after c.
Ctrl-d / Ctrl-uScroll half page down / up.
:42Jump to line 42.

f then ; to repeat the search forward; , to repeat backward.

Operators

Operators act on a motion: operator + motion or operator + text-object.

OperatorAction
dDelete (cut).
cChange (delete and enter Insert).
yYank (copy).
> / <Indent / de-indent.
=Auto-indent.
gU / guUppercase / lowercase.

Doubles apply to the whole line: dd deletes a line, yy yanks a line, cc changes a line.

Common text objects used with operators:

Text objectSelects
iw / awInner word / a word (includes surrounding space).
i" / a"Inside / around double quotes.
i( / a(Inside / around parentheses.
i{ / a{Inside / around braces.
it / atInside / around an HTML tag.
ip / apInner / a paragraph.

ci" changes everything inside double quotes. da( deletes a parenthesized expression including the parens.

Search and replace

Search is a motion; use it to drive operators.

CommandWhat it does
/patternSearch forward. n next, N previous.
?patternSearch backward.
* / #Search forward / backward for the word under cursor.
:%s/old/new/gReplace all occurrences in the file.
:%s/old/new/gcReplace with confirmation at each occurrence.
:10,20s/old/new/gReplace in lines 10 to 20.
:'<,'>s/old/new/gReplace in visual selection (populated automatically after V).
:nohClear search highlight.

Patterns use Vim regex. Use \v (very magic mode) for PCRE-like syntax: :%s/\v(\w+)@(\w+)/\1 at \2/g.

Registers and macros

Registers are named clipboards; macros record keystrokes into a register.

CommandWhat it does
"ayyYank a line into register a.
"apPaste from register a.
"+yYank to the system clipboard.
"+pPaste from the system clipboard.
:regShow all register contents.
qaStart recording a macro into register a.
qStop recording.
@aPlay macro a.
10@aPlay macro a ten times.
@@Replay the last macro.

Design macros to be repeatable: end with a motion that positions the cursor for the next invocation.

Common gotchas

  • Pressing u in Insert mode undoes a character; in Normal mode it undoes the last change. If your undos feel too granular, break insert sessions with Esc between logical chunks.
  • x deletes into the unnamed register, overwriting your last yank. Yank into a named register ("ay) before deleting if you need to paste the yanked text later.
  • :q! discards unsaved changes without confirmation. Use :wqa to write all buffers and quit.
  • dd on a blank line still puts the newline in the register. "_dd sends the delete to the black-hole register and leaves the clipboard alone.
  • Vim regex is not PCRE. + requires \+ without \v. Use \v at the start of a pattern to enable very magic mode and write +, (), | without backslashes.
  • :set paste before pasting from the system clipboard in Insert mode to prevent autoindent from mangling indentation. Reset with :set nopaste. Neovim does not need this.