How do I apply a macro to every line in a specific range without running it manually each time?
:[range]normal @q
The :[range]normal @q command replays the macro in register q on every line within a given range.
:[range]normal @q
The :[range]normal @q command replays the macro in register q on every line within a given range.
{count}@{register}
Prefix any macro execution with a count to repeat it that many times in a single command.
:let @q =
Instead of recording a macro with q, you can assign any string directly to a named register using :let @{register} = 'keys'.
@"
Vim macros are stored in registers — and you can execute any register as a macro with @{register}.
:argdo norm @a | update
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
:let @q = 'commands'
Macros in Vim are just text stored in named registers.
:let @q = "dwelp"
Recording macros with q works well for simple sequences, but complex macros with special keys can be hard to get right in one take.
qQ...q
When you record a macro into register q with qq.
:put a ... edit ... "ayy
Recorded macros are stored as plain text in registers, but editing them by re-recording is tedious for complex sequences.
qqqqqq{edits}@qq
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
qaq qa...@aq @a
A recursive macro calls itself at the end of its recording, causing it to repeat indefinitely until a command inside it fails (like a search hitting the end of
qaqqa{actions}@aq@a
A recursive macro is a macro that calls itself at the end of its recording.
qq;.q then @q or @@
The dot command (.
:wviminfo / :rviminfo
Vim can persist register contents (including macros) across sessions using viminfo (Vim) or shada (Neovim).
qa...@aq
A recursive macro calls itself at the end of its recording, causing it to repeat until a motion or search fails.
/pattern<CR>cgnreplacement<Esc>.
The gn text object selects the next search match, and cgn changes it.
qa/pattern<CR>dd@aq
By starting a macro with a search command, the macro becomes conditional — it jumps to the next match before acting, and terminates when no more matches are f
:let g:debug_macro=1 | normal @a
When a macro doesn't work as expected, debugging it step by step is essential.
qqq qq{commands}@qq @q
A recursive macro calls itself at the end of its recording, causing it to repeat automatically until a motion fails (like j at the last line).
qa Yp <C-a> q
By combining a macro with (increment number), you can quickly generate numbered sequences.