How do I programmatically create a blockwise register with setreg()?
:call setreg('a', "foo\nbar", 'b')
Most register examples focus on interactive yanks, but setreg() lets you construct registers programmatically, including their type.
:call setreg('a', "foo\nbar", 'b')
Most register examples focus on interactive yanks, but setreg() lets you construct registers programmatically, including their type.
:keepjumps normal! 500@q
Running a macro hundreds of times is efficient, but it can flood your jumplist and make normal navigation painful afterward.
qqgUiwjq2@q
Macros are strongest when the edit pattern is stable but too awkward for a one-liner substitute.
:'<,'>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.
:bufdo if &buftype ==# '' | update | endif
bufdo is powerful for multi-buffer automation, but a naive write pass can error on special buffers (help, terminal, quickfix, prompts).
buffers-windows #buffers #windows #ex-commands #automation #workflow
:cdo normal! @q
When a refactor target spans many files but only specific matches matter, running a macro globally is risky.
:echo string(getreg('q'))
Macros can fail for subtle reasons: hidden control keys, extra whitespace, or unexpected register contents.
registers #registers #macros #debugging #automation #command-line
: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
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
qa...@aq
A recursive macro calls itself at the end of its recording, causing it to repeat until a motion or search fails.
:call feedkeys("iHello\<Esc>", 'n')
The feedkeys() function injects keystrokes into Vim's input buffer as if the user typed them.
:cwindow
The :cwindow command intelligently manages the quickfix window — it opens the window only if there are entries in the quickfix list, and closes it if the list
qaqqa...@aq
A recursive macro calls itself at the end of its recording, creating a loop that repeats until a motion or command fails (like reaching the end of the file or f
:bufdo normal @a
The :bufdo command executes an Ex command in every open buffer, and when combined with :normal @a, it replays macro a across all of them.
macros #macros #buffers #ex-commands #automation #productivity
:g/pattern/normal @a
The :g (global) command combined with :normal @a lets you execute a recorded macro only on lines matching a pattern.
macros #macros #ex-commands #global-command #editing #automation
qaYp<C-a>q99@a
By recording a macro that duplicates a line and increments its number, you can generate a numbered list of any length with a single replay command.
macros #macros #editing #normal-mode #automation #productivity
qa ... q ... @a
Macros let you record a sequence of commands and replay them.