vim command

Vim Macros: Record and Replay Edits

Learn macro recording and replay patterns to automate repetitive edits in Vim.

Published: 2026-03-09Updated: 2026-03-09
Macros let you capture one clean edit sequence and replay it across many targets.

Record a macro

Start with q{register}, perform the edit, and stop with q. Replay with @{register} or a count prefix.

Make macros stable

Use motions that are resilient to line differences and test on a second line before bulk replay.

Common Mistakes

  • Recording accidental cursor moves.
  • Skipping a dry-run before replaying with a count.

FAQ

What register should I use for macros?

Use temporary registers like a or b while practicing, and overwrite as needed.

Can macros call other macros?

Yes, but keep nested macros short to avoid hard-to-debug loops.

Practice This Now