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

How do I replay a macro many times without cluttering the jumplist?

Answer

:keepjumps normal! 500@q

Explanation

Running a macro hundreds of times is efficient, but it can flood your jumplist and make normal navigation painful afterward. Wrapping macro replay in :keepjumps keeps your history clean while still performing a large batch operation.

How it works

:keepjumps normal! 500@q
  • :keepjumps prevents jump-list updates from the command it prefixes
  • normal! executes Normal-mode keys literally (ignores user mappings)
  • 500@q replays macro register q up to 500 times

This is especially useful for structured edits where each macro run moves to the next target and may fail naturally at the end. You still get fast automation, but you avoid a polluted jumplist that would otherwise break <C-o> and <C-i> navigation flow.

Example

Suppose macro q edits one matching line and moves to the next candidate. Instead of manually pressing @q repeatedly, run:

:keepjumps normal! 500@q

The macro executes in bulk, and your jump history remains focused on meaningful navigation points.

Tips

  • Pick a count safely above expected matches (for example 200 or 1000)
  • Keep normal! instead of normal for deterministic behavior
  • Pair with :set lazyredraw temporarily when replaying very large macro batches

Next

How do I programmatically create a blockwise register with setreg()?