How do I run a recorded macro on every line in a range without using a count?
:[range]norm @{register}
The :normal command executes normal-mode keystrokes on each line in a range — including macro playback.
:[range]norm @{register}
The :normal command executes normal-mode keystrokes on each line in a range — including macro playback.
qq{cmds}@qq
A recursive macro is one that calls itself at the end of its own body.
:keeppatterns {cmd}
Whenever Vim runs a command that involves searching — :g, :s, :v, or even moving the cursor with / — it overwrites the last search register (@/).
:keepjumps {cmd}
:keepjumps is a command modifier that suppresses any jump list updates caused by the command that follows it.
qa{actions}@aq
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.
:normal!
The :normal! command (with !) executes normal mode keystrokes exactly as Vim defines them, ignoring any user-defined mappings.
:let @q = @:
The : register always holds the last Ex command you ran.
qqq
Pressing qqq in normal mode is the quickest way to empty a macro register.
:let @a = 'text'
Vim's :let command lets you assign a value directly to any named register without performing a yank or delete operation.
registers #registers #macros #vimscript #ex-commands #normal-mode
:argdo normal @a
The :argdo command applies any Ex command to every file in the argument list.
:execute
:execute evaluates a string as an Ex command, letting you build commands dynamically or embed special key sequences (like or ) as literal characters.
: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
:let @q = 'content'
:let @{reg} = 'string' directly assigns content to any named register from Vimscript.
5@q
Prefix the @ macro-execution command with a count to run the macro that many times in a row.
let @q = 'keystrokes'
Macros recorded with q{register} are stored in registers and lost when Vim exits.
{N}@q
Prefix a macro invocation with a count to execute it up to N times in a single command.
: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.
]q
The vim-unimpaired plugin (by Tim Pope) provides a consistent [x / ]x mnemonic for navigating any list-like structure in Vim.
:let @q = "dd"
Macros are just strings stored in named registers.
:let @a="text"
:let @{register}=".