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
@athat makes 10 changes - A single
uundoes 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
Uis different — it undoes all changes on the current line- If a macro with a count (
50@a) makes wrong changes,uundoes one iteration 5uundoes 5 iterations of the macro- Always test macros on a small sample before running with large counts