How do I create a self-repeating macro that runs until there is nothing left to process?
@q (inside macro recording)
A recursive macro calls itself as its last action, causing it to repeat indefinitely until it hits an error (like reaching end of file or failing a search).
category:
macros
tags:
#macros
#registers
#normal-mode
#editing
How do I run a recorded macro on every line in a range without using a count?
The :normal command executes normal-mode keystrokes on each line in a range — including macro playback.
category:
macros
tags:
#macros
#ex-commands
#normal-mode
#editing
How do I create a macro that repeats itself until it hits an error or end of file?
A recursive macro is one that calls itself at the end of its own body.
category:
macros
tags:
#macros
#registers
#normal-mode
How do I write a Vim macro that automatically repeats until it fails?
A recursive macro is one that calls itself as its final action, causing it to repeat indefinitely until any command in the body fails (e.
category:
macros
tags:
#macros
#registers
#normal-mode
#editing
How do I run normal mode commands in a script or macro without user mappings interfering?
The :normal! command (with !) executes normal mode keystrokes exactly as Vim defines them, ignoring any user-defined mappings.
category:
macros
tags:
#macros
#ex-commands
#normal-mode
#editing
How do I save my last Ex command into a register so I can replay it as a macro?
The : register always holds the last Ex command you ran.
category:
macros
tags:
#macros
#registers
#ex-commands
#workflow
How do I clear a macro register to start fresh without using Vimscript?
Pressing qqq in normal mode is the quickest way to empty a macro register.
category:
macros
tags:
#macros
#registers
#normal-mode
How do I run a recorded macro on every file in my argument list at once?
The :argdo command applies any Ex command to every file in the argument list.
category:
macros
tags:
#macros
#ex-commands
#argdo
#normal-mode
#editing
How do I run a macro a dynamically computed number of times or interleave it with other commands?
:for i in range(1,10) | execute "normal @q" | endfor
Using a Vimscript :for loop with execute "normal @q" lets you run a macro with a dynamically computed iteration count and interleave other Ex commands between i
category:
macros
tags:
#macros
#ex-commands
#normal-mode
How do I execute a recorded macro a specific number of times?
Prefix the @ macro-execution command with a count to run the macro that many times in a row.
category:
macros
tags:
#macros
#registers
#normal-mode
#editing
How do I save a recorded macro permanently so it survives Vim restarts?
Macros recorded with q{register} are stored in registers and lost when Vim exits.
category:
macros
tags:
#macros
#registers
#config
How do I run a macro a specific number of times without using a recursive macro?
Prefix a macro invocation with a count to execute it up to N times in a single command.
category:
macros
tags:
#macros
#registers
#normal-mode
#editing
How do I edit the contents of a macro register without re-recording it?
:let @q = substitute(@q, 'old', 'new', 'g')
When a recorded macro has a typo or needs a small tweak, re-recording the entire thing is error-prone.
category:
macros
tags:
#macros
#registers
#editing
#normal-mode
How do I create or edit a Vim macro as a plain string without re-recording it?
Macros are just strings stored in named registers.
category:
macros
tags:
#macros
#registers
#ex-commands
How do I create a macro that repeats itself automatically until there is nothing left to process?
A recursive macro calls itself at the end of its own definition, causing it to run repeatedly until Vim hits an error — such as reaching the end of the file o
category:
macros
tags:
#macros
#registers
#editing
#normal-mode
How do I split a complex Vim macro into reusable subroutines?
Record worker macro in @b, call it from @a with @b
Complex macros are hard to debug and maintain when crammed into a single register.
category:
macros
tags:
#macros
#registers
#editing
How do I inspect what key sequences are stored in a macro register?
When a macro behaves unexpectedly, :echo strtrans(@q) reveals exactly what is stored in register q—including invisible control characters—as human-readable
category:
macros
tags:
#macros
#registers
#debugging
How do I define or modify a macro directly as a string without recording it?
Macros in Vim are stored in registers as plain text.
category:
macros
tags:
#macros
#registers
#ex-commands
#normal-mode
How do I apply a recorded macro to every line in a visual selection?
Combining :normal with a visual range lets you replay a macro on each line of a selection individually — far more targeted than recursive macros or @@ repeati
category:
macros
tags:
#macros
#ex-commands
#normal-mode
#visual-mode
How do I create a macro that runs continuously until it hits an error?
A recursive macro is a macro that calls itself as its last step, causing it to loop automatically until an operation fails (such as reaching the end of the file
category:
macros
tags:
#macros
#registers
#normal-mode
#editing