How do I create a recursive macro that repeats itself until it fails?
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
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.
"+q{keys}q
You can record macros into any register, including the system clipboard (+).
@a (within macro @b)
Vim macros can call other macros, enabling modular macro composition.
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
:nnoremap <leader>x :norm! @a<CR>
Once you've perfected a macro by recording and testing it, you can make it permanent by converting it into a mapping in your vimrc.
: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.
:normal! {keys}
:normal {keys} executes keystrokes as if typed in Normal mode — but it respects your custom mappings and abbreviations.
When recording a macro, you can execute another macro inside it by pressing @b (or any register) during the recording.
:ldo execute 'normal @q'
:ldo runs an Ex command on each entry in the location list — the buffer-local cousin of the quickfix list.
:argdo execute 'normal @q' | update
:argdo runs an Ex command on every file in Vim's argument list (the arglist).
:set lazyredraw
When Vim runs a macro or an :argdo / :bufdo loop, it redraws the screen after every command by default.
:let @q = '{keystrokes}'
You can assign a string directly to any register using :let @{reg} = '.