How do I make a macro repeat itself until it fails?
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
2277 results for "@a"
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.
:cdo normal! @a | update
When you already have a precise quickfix list, :cdo is one of the safest ways to run a macro only where it matters.
{count}%
When used with a count, the % command jumps to the line at that percentage of the file.
:'a,'bnormal! @q<CR>
When you need to replay a macro on a precise region, selecting lines manually can be slow and error-prone.
qaI// <Esc>jq
This macro adds a // comment prefix to the beginning of the current line and moves down.
:@a
How it works The command :@a executes the contents of register a as an Ex command.
5"ap
Prefix the paste command with a count.
:let @a = execute('messages')
The execute() function (added in Vim 8.
:'<,'>normal @q
The :'normal @q command runs macro q on every line of the visual selection.
:let @a = @"
Vim's :let command lets you read and write register contents as strings, making it possible to copy, combine, or modify register values without ever leaving the
:terminal ++curwin
By default, :terminal opens a new split window for the terminal emulator.
buffers-windows #terminal #buffers #windows #shell #ex-commands
v/pattern<CR>
Starting a search while in visual mode extends the selection to the search match.
qaf'r"q
Record a macro that finds the next single quote with f' and replaces it with a double quote using r".
"aVaBy
Position cursor in a function, use VaB to visually select the block including braces, then "ay to yank into register a.
:b name
Use :b with a partial filename.
qaf,i"<Esc>la"<Esc>q
Record a macro that finds the next comma, inserts a quote before it, moves past the comma, and inserts a quote after.
:'<,'>s/\%Vpattern/replacement/g
Using \%V in a substitute pattern restricts matching to within the visual block area only, rather than the full lines.
ma and 'a
The ma command sets a mark named a at the current cursor position.
:let @b = @a
The :let @b = @a command copies the contents of register a into register b.