C.W.K.
Stream
Lesson 08 of 08 · published

The Dot Command — Vim's Hidden Superpower

~11 min · vim, productivity, dot-formula

Level 0Trapped
0 XP0/35 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

One key to repeat them all

If you learn a single "advanced" Vim command from this entire quest, make it the dot command: . repeats your last change. It is easily the most powerful single keystroke in Vim, and it's the engine behind why experienced users look so fast.

What counts as a "change"

A change is anything that modifies the buffer between entering and leaving Normal mode. Examples:

  • dd — delete a line. . deletes the next line.
  • cwhelloEsc — change a word to "hello". . changes the next word to "hello".
  • A;Esc — append a semicolon. . appends a semicolon to whichever line you're on now.
  • I//Esc — comment-out a line. . comments-out the next line you point at.

The dot formula

Drew Neil's Practical Vim distilled the essence: one keystroke to move, one keystroke to repeat the change. Your edit loop becomes n., j., ;. — find next, repeat. Once your fingers find this rhythm, batch edits feel like playing a metronome instead of typing.

Structure your edits to be dot-repeatable. Prefer cw over dwi (one change vs two). Prefer A; over $a;. The first edit is the same speed; the difference shows up on edits two through ten when you press . and the previous version doesn't replay correctly.

Two patterns you'll use forever

Pattern 1: search + dot. Use / or * to find the next occurrence, make a change, then n., n., n. — done across the whole file. The search command itself is repeated by n, and the change is repeated by .. Two hand motions, infinite reach.

Pattern 2: line jump + dot. Make the change once, then j., j., j. walks down the file applying it. Or }. to jump by paragraphs. Or }.}.. Each repeat costs you exactly two keys.

What dot doesn't repeat

  • Pure motion — j, w, $ aren't changes, so dot ignores them.
  • Command-line operations like :s/old/new/g. Use & or :& for those.
  • Macros — those have their own replay key, @@.

Code

Pattern 1 — adding semicolons to many lines·vim
" Goal: append a ; to the end of every line in a block.
" Step 1: navigate to the first line.
" Step 2: A; <Esc>     — appends ; , leaves Insert mode
" Step 3: j.            — down a line, repeat the change
" Step 4: j. j. j.     — keep walking
" That's it. Two keys per line after the first.
Pattern 2 — search + dot to remove a parameter from many calls·vim
" Goal: remove all occurrences of `, debug=True` from a Python file.
" Step 1: /, debug=True<Enter>     — search and land on the first match
" Step 2: dt)                       — delete up to (not including) the )
"          (now the first one is gone)
" Step 3: n.                        — find next, repeat the deletion
" Step 4: n.  n.  n.               — until ?: "Pattern not found"
What dot remembers — verify it yourself·vim
:help single-repeat
" Vim's own canonical reference for what . repeats.

External links

Exercise

Open a source file with at least 10 lines containing the string print( (or any repeated pattern). Use the dot formula to rename every print( to logger.info(: search for /print(, change with cw, type logger.info(, hit Esc, then walk through the file with n. until "Pattern not found." That's it — that's the rhythm.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.