Vim Undo, Redo, and Repeat — u, Ctrl+r, .

Learn Vim's undo tree, redo, and the powerful dot command for repeating changes. Understand u, Ctrl+r, and the . command that experienced Vim users rely on constantly.

Editing

Detailed Explanation

Undo and Redo

Command Action
u Undo the last change
Ctrl+r Redo (undo the undo)
U Undo all changes on the current line
{n}u Undo the last n changes

Vim's Undo Tree

Unlike most editors that have a linear undo history, Vim maintains an undo tree. If you undo several changes and then make a new edit, the previous redo history is not lost — it becomes a branch in the undo tree. You can navigate this tree with:

  • g- — Go to an older text state
  • g+ — Go to a newer text state
  • :earlier 5m — Go to the text state from 5 minutes ago
  • :later 10s — Go to the text state 10 seconds forward

The Dot Command (.)

The . command repeats the last change. This is arguably Vim's most powerful feature:

Example workflow:

  1. ciwfoo — Change the word under cursor to "foo"
  2. Move to another word
  3. . — Change that word to "foo" too

What counts as a "change":

  • Everything from entering Insert mode to leaving it
  • Any Normal mode command that modifies text (x, dd, >>, etc.)
  • A substitution command

Combining Dot with Search

The killer pattern is combining . with n:

  1. /oldWord — Search for the word
  2. cwNewWord — Change it
  3. n — Jump to next match
  4. . — Repeat the change
  5. Repeat steps 3-4 as needed

This gives you manual control over each replacement, which :%s does not.

Use Case

You need to undo mistakes, redo changes, or apply the same edit to multiple places in a file using Vim's dot repeat command for efficient repetitive editing.

Try It — Vim Cheat Sheet

Open full tool