How do I run a macro only between two marks without entering Visual mode?
:'a,'bnormal! @q<CR>
When you need to replay a macro on a precise region, selecting lines manually can be slow and error-prone.
:'a,'bnormal! @q<CR>
When you need to replay a macro on a precise region, selecting lines manually can be slow and error-prone.
:'<,'>normal @@
When you already have a useful macro but need to apply it to a specific block of lines, :'normal @@ is a high-leverage pattern.
:cdo normal! @q
When a refactor target spans many files but only specific matches matter, running a macro globally is risky.
:let @q .= "j^"
Live macro recording is fast, but adjusting the tail of a macro by re-recording can be risky once it already works in most places.
macros #macros #registers #automation #normal-mode #workflow
:wn
:wn (short for :wnext) writes the current buffer to disk and immediately advances to the next file in the argument list.
mode()
The mode() function returns a short string identifying the current editing mode — 'n' for Normal, 'i' for Insert, 'v' for Visual character-wise, 'V' for Visua
macros #macros #normal-mode #visual-mode #insert-mode #editing
input({prompt})
The built-in input() function pauses execution, displays a prompt at the bottom of the screen, and returns whatever the user types before pressing Enter.
:let @q .= "keys"
The string concatenation assignment :let @q .
"qp {edit} 0"qy$ dd
When you record a macro and realize it has a mistake, the easiest fix is to paste the macro's keystrokes as text, edit them, and yank the corrected version back
Q
In Neovim, the Q key is mapped to replay the last executed macro — the same as @@ in both Vim and Neovim.
qaq qa...@aq
A recursive macro calls itself at the end of its recording, causing it to repeat automatically until an error — such as reaching the end of the file — stops
qa{motions}@aq
A recursive macro is one that calls itself at the end of its own recording.
qa<C-a>jq
By recording a one-step macro that increments a number and moves down a line, you can bulk-apply across as many lines as needed with a single count.
:let @q = substitute(@q, 'old', 'new', '')
Vim macros are stored as plain text in named registers, which means you can inspect and modify them directly using :let and :echo.
999@q
Prefixing a macro invocation with a large count like 999@q tells Vim to run register q up to 999 times.
qqq then qq{commands}@qq
A recursive macro in Vim calls itself at the end of its body, repeating automatically until one of its commands fails.
:let @q = substitute(@q, 'from', 'to', 'g')
Macros are stored as plain text in named registers, so you can manipulate them with any Vimscript string function.
:execute "normal! \<{key}>"
When building dynamic :execute normal! calls in Vimscript, you must use double-quoted strings with the \ notation so Vim interprets the special key codes.
:[range]normal @a
The :[range]normal @a command runs a recorded macro against every line in a given range.
macros #macros #registers #ex-commands #normal-mode #advanced
:g/./norm @q
Combining the :global command with :normal lets you run a macro on every non-blank line in one shot.