vimtricks.wiki Concise Vim tricks, one at a time.

How do I undo the last change in Vim?

Answer

u

Explanation

The u command undoes the last change you made in normal mode. Vim maintains a full undo history, so you can press u repeatedly to step back through every change you have made since opening the file.

How it works

  • u reverses the most recent change
  • Each press of u steps one change further back in history
  • Vim tracks undo history as a tree, not just a linear stack

Example

Given the text:

Hello world

You change world to Vim using ciwVim<Esc>, resulting in:

Hello Vim

Pressing u reverts it back to:

Hello world

Tips

  • Use U to undo all changes on the current line (less commonly used)
  • Use <C-r> to redo (reverse an undo)
  • Use :earlier 5m to jump back to the state from 5 minutes ago
  • Use :later 5m to jump forward in time
  • Vim's undo is a tree — if you undo and then make a new change, the old branch is preserved and accessible with g- and g+
  • Use :undolist to see the undo branches available

Next

How do I edit multiple lines at once using multiple cursors in Vim?