How do I make a macro that finds and operates on specific patterns?
qq /pattern<CR> {commands} q
By incorporating a search command inside a macro, you can make it jump to the next occurrence of a pattern before performing its edits.
272 results for ":q"
qq /pattern<CR> {commands} q
By incorporating a search command inside a macro, you can make it jump to the next occurrence of a pattern before performing its edits.
:call setreg('q', 'dd')
The setreg() VimScript function lets you populate any register with arbitrary content directly from the command line or a script — no recording required.
:argdo execute 'normal @q' | update
:argdo runs an Ex command on every file in Vim's argument list (the arglist).
:cdo normal! @q
When a refactor target spans many files but only specific matches matter, running a macro globally is risky.
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).
:while search('TODO') | normal! @q | endwhile
A fixed count like 100@q is brittle: sometimes your macro needs 12 passes, sometimes 300, and over-running can corrupt already-processed text.
macros #macros #automation #search #normal-mode #ex-commands
999@q
Prefixing a macro invocation with a large count like 999@q tells Vim to run register q up to 999 times.
:call setreg('q', keys, 'c')
The setreg() function writes any string directly into a named register, letting you construct macro keystrokes from Vimscript expressions rather than live recor
q: or <C-f> from : prompt
The command-line window (q:) opens a full Vim buffer containing your Ex command history.
:'a,'bnormal! @q<CR>
When you need to replay a macro on a precise region, selecting lines manually can be slow and error-prone.
qa ci"replacement<Esc> /next<CR> q
Macros can contain any Vim command including text objects, searches, and multi-key motions.
qa Yp <C-a> q
By combining a macro with (increment number), you can quickly generate numbered sequences.
:ldo execute 'normal @q'
:ldo runs an Ex command on each entry in the location list — the buffer-local cousin of the quickfix list.
q/
How it works Vim keeps a history of all your search patterns.
:windo normal! @q
When you split a file into multiple windows or keep several related buffers visible, repeating the same small cleanup in each one can be tedious.
macros #macros #windows #normal-mode #ex-commands #automation
1000@q
Vim macros stop executing the moment any step in the macro causes an error — a failed search, a motion that cannot proceed, or a substitution with no matches.
When recording a macro, you can execute another macro inside it by pressing @b (or any register) during the recording.
q:
The command-line window is a special buffer that shows your entire Ex command history and lets you edit entries using the full power of Vim's normal mode before
command-line #command-line #ex-commands #history #editing #productivity
qa<C-r>=expression<CR>q
How it works The expression register (=) lets you evaluate Vimscript expressions and insert the result.
:cnoreabbrev {lhs} {rhs}
:cnoreabbrev defines a non-recursive command-line abbreviation — like noremap but for Ex commands.