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

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

  • :windo executes a command in each window from left-to-right/top-to-bottom
  • normal! runs raw Normal-mode keys, ignoring custom mappings
  • @q executes the macro stored in register q
  • 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! over normal so user mappings do not alter macro behavior mid-run.

Next

How do I preview a fuzzy tag match in the preview window without immediately switching buffers?