How do I create a recursive macro that runs until it encounters an error?
qa...@aq
A recursive macro calls itself at the end of its recording, causing it to repeat until a motion or search fails.
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).
:let @q = '{keystrokes}'
You can assign a string directly to any register using :let @{reg} = '.
:%normal @q
To apply a macro to every line in the file, use :%normal @q.
:'<,'>norm @q
When you visually select lines and then type a : command, Vim automatically inserts ' (the visual range marks) into the command line.
"qp
Macros are stored as plain text in named registers.
100@a
When you give a large count to a macro — such as 100@a — Vim automatically stops replaying the macro as soon as any step inside it fails.
@=
The @= command lets you type a Vimscript expression and execute the result as if it were a macro.
"ap, edit, 0"ay$
When a macro has a small mistake, re-recording the entire thing is tedious.
qaciWmyFunc(<C-r>")<Esc>q
Record a macro that changes the inner word, types the function name with opening paren, pastes the original word from the register, and closes the paren.
qaq:g/pattern/normal "Ayy
Clear register a with qaq, then use :g/pattern/normal "Ayy to append all matching lines to register a.