The Vim dot command: repeat the last change

Press . in Normal mode and Vim repeats your last change at the cursor: the delete, the change, the insert, the paste. It is one key, it works with almost anything, and it is the reason Vim users plan their edits as "one change, then repeat".

What counts as a change

The dot command repeats the last command that changed the text. That includes:

Moving the cursor and copying (y) are not changes, so you can move anywhere in between. Undo (u) is not repeated either. A change that included typed text repeats that exact text.

Repeat a delete

BeforeKeysAfter
hello worldx..lo world
one two three fourdw..four
a / b / c / d (one per line)dd.c / d

A count in front of the dot replaces the old count. After dw on one two three four, 2. deletes two words at once and leaves four.

Repeat an insert

Dot remembers what you typed in Insert mode. Add a semicolon to the end of three lines by doing it once and repeating:

BeforeKeys (cursor on line 1)After
apple = 1 / pear = 2 / plum = 3A;<Esc>j.j.apple = 1; / pear = 2; / plum = 3;

A appends at the end of the line wherever the cursor is, so j. works on every line. That is why A; repeats better than $a;, which needs two commands to describe the same change.

Change, move, repeat

The classic rhythm is: make one change, jump to the next place with a motion, press .. Here every var becomes let:

BeforeKeysAfter
var a = 1; var b = 2; var c = 3;cwlet<Esc>fv.;.let a = 1; let b = 2; let c = 3;

Step by step: cwlet<Esc> changes the first word. fv jumps to the v of the next var, and . repeats the change. ; repeats the f search, so ;. does the next one. The same rhythm works with n. after a search such as /var.

Dot with text objects

Text objects make dot reliable, because the change describes a whole thing and does not depend on where in it the cursor stood. See Vim text objects explained for the full list.

Before (cursor on hi)KeysAfter
say "hi" / say "yo"ci"bye<Esc>j0.say "bye" / say "bye"

After j0 the cursor is at the start of line 2, outside the quotes. ci" still finds the string, so . works.

Edits that repeat well

In real Vim, dot is often followed by macros (q) for longer sequences. Vimrealm teaches dot but not macros yet.

The dot command is taught in the Hall of Echoes (chapter 10) of Vimrealm, together with yank and put, in quests scored by keystrokes.

Play Vimrealm free

Chapters 1–5 (movement) are free. The dot command is in chapter 10, which is part of the full version ($7.99, one payment). See how the course works or keep the cheat sheet entry for yank, put and dot open while you practise.