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

How do I undo all changes made by a macro?

Answer

u after macro (single undo)

Explanation

When a macro makes multiple changes, a single u undoes the entire macro as one unit. Each macro execution is treated as one undo step.

How it works

  • Run a macro with @a that makes 10 changes
  • A single u undoes all 10 changes at once
  • Vim groups all changes within a macro into one undo block

Example

A macro that changes three words on a line: after running @a, pressing u reverts all three word changes.

Tips

  • This makes macros safe to experiment with
  • U is different — it undoes all changes on the current line
  • If a macro with a count (50@a) makes wrong changes, u undoes one iteration
  • 5u undoes 5 iterations of the macro
  • Always test macros on a small sample before running with large counts

Next

How do you yank a single word into a named register?