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 programmatically set the contents of a register from the command line?
The :let @{reg} = expr command lets you assign any string or expression directly into a named register without entering insert mode or performing a yank.
category:
registers
tags:
#registers
#ex-commands
#macros
#normal-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
How do I create a custom Vim operator that works with any motion or text object?
Vim's operatorfunc option lets you define your own operators — just like the built-in d, y, or c — that accept any motion or text object.
category:
config
tags:
#config
#macros
#vimscript
#normal-mode
How do I apply a macro to every line in a specific range without running it manually each time?
The :[range]normal @q command replays the macro in register q on every line within a given range.
category:
macros
tags:
#macros
#normal-mode
#ex-commands
#ranges
How do I run a macro a specific number of times at once?
Prefix any macro execution with a count to repeat it that many times in a single command.
category:
macros
tags:
#macros
#registers
#normal-mode
How do I define or modify a macro without recording keystrokes?
Instead of recording a macro with q, you can assign any string directly to a named register using :let @{register} = 'keys'.
category:
macros
tags:
#macros
#registers
#ex-commands
#normal-mode
How do I run text I've yanked or typed as a Vim macro without recording it first?
Vim macros are stored in registers — and you can execute any register as a macro with @{register}.
category:
macros
tags:
#macros
#registers
#editing
#normal-mode
How do I apply a normal mode command to every line in a range at once?
:normal (abbreviated :norm) executes a sequence of normal-mode keystrokes on each line of an address range.
category:
command-line
tags:
#ex-commands
#editing
#normal-mode
#macros
How do I run a recorded macro across multiple files at once?
Combining :argdo with :norm @a lets you apply a recorded macro to every file in Vim's argument list — a powerful pattern for bulk refactoring across a project
category:
macros
tags:
#macros
#ex-commands
#editing
#buffers
How do I define or fix a macro using Vimscript instead of re-recording it?
Macros in Vim are just text stored in named registers.
category:
macros
tags:
#macros
#registers
#ex-commands
How do I create a macro by typing it out instead of recording it interactively?
Recording macros with q works well for simple sequences, but complex macros with special keys can be hard to get right in one take.
category:
macros
tags:
#macros
#registers
#ex-commands
How do I add more steps to an existing macro without re-recording it from scratch?
When you record a macro into register q with qq.
category:
macros
tags:
#macros
#registers
#recording
#editing
How do I modify the contents of a register without re-recording it?
:let @a = substitute(@a, 'old', 'new', 'g')
After recording a macro or yanking text into a named register, you may need to tweak it — fix a typo in a recorded macro, change a variable name in yanked tex
category:
registers
tags:
#registers
#macros
#ex-commands
#editing
How do I edit a recorded macro by modifying it as text in a buffer?
Recorded macros are stored as plain text in registers, but editing them by re-recording is tedious for complex sequences.
category:
macros
tags:
#macros
#registers
#editing
How do I create a recursive macro that repeats itself until it fails?
A recursive macro calls itself at the end of its sequence, creating a loop that automatically repeats until a motion or command fails (such as hitting the last
category:
macros
tags:
#macros
#editing
#normal-mode
#registers