How do I execute a recorded macro once in each currently open window?
Answer
:windo normal! @q
Explanation
When you split a file into multiple windows or keep several related buffers visible, repeating the same small cleanup in each one can be tedious. :windo normal! @q applies a recorded macro register to every open window in turn, which is faster and more consistent than manually switching and replaying. This is especially effective for view-local edits, quick annotations, or one-pass refactors that depend on what each window currently shows.
How it works
:windoexecutes a command in each window from left-to-right/top-to-bottomnormal!runs raw Normal-mode keys, ignoring custom mappings@qexecutes the macro stored in registerq- Combined, Vim enters each window, runs your macro exactly once, then moves to the next window
Example
Suppose you have three windows open and each contains TODO comments that you want to normalize with a macro in register q (for example, turning TODO: into TODO(finn):).
Before:
Window 1: // TODO: validate input
Window 2: # TODO: add retries
Window 3: -- TODO: remove debug flag
After :windo normal! @q:
Window 1: // TODO(finn): validate input
Window 2: # TODO(finn): add retries
Window 3: -- TODO(finn): remove debug flag
Tips
- Dry-run first with a no-op macro on scratch content to confirm it is safe in every window.
- If some windows should be skipped, close them temporarily or use a narrower command scope.
- Prefer
normal!overnormalso user mappings do not alter macro behavior mid-run.