How do I create a macro that uses an incrementing counter?
Use :let i=1 with macro
By combining a Vimscript variable with a macro, you can create sequences with incrementing numbers.
Use :let i=1 with macro
By combining a Vimscript variable with a macro, you can create sequences with incrementing numbers.
":
The : register contains the last Ex command that was executed.
"=2+3<CR>p
The expression register = evaluates a Vimscript expression and stores the result.
:let @a = ""
The :let @{register} = "" command empties a register.
"ap, edit, "add
Since macros are stored in registers, you can paste the register content into the buffer, edit it, and yank it back.
y (in visual mode)
In visual mode, pressing y yanks (copies) the selected text into the default register.
visual select + d, move, P
To swap two pieces of text, delete the first selection, navigate to the second, select it, and paste.
y/<C-r>"<CR>
To search for the exact text you have selected in visual mode, yank it and paste it into the search prompt.
<C-v>jj"ay then "ap
How it works Vim registers remember not just the text content but also the type of selection that was used to yank it: characterwise, linewise, or blockwise.
:call setreg('a', @a . 'text', 'l')
How it works Vim provides two functions for advanced register manipulation: setreg() and getreg().
:%s/pattern/\=@a/g
How it works In Vim's substitute command, the replacement string can be a Vimscript expression when prefixed with \=.
:@a
How it works The command :@a executes the contents of register a as an Ex command.
"*p vs "+p
How it works Vim has two system clipboard registers that interact with the operating system: " -- the selection register (PRIMARY selection on Linux/X11, clipbo
/<C-r>0
How it works After yanking text, you can use it directly as a search pattern by inserting the yank register contents into the search prompt.
:<C-r>a
How it works While typing an Ex command on the command line (after pressing :), you can insert the contents of any register by pressing Ctrl-R followed by the r
:{line}put {register}
How it works The :put Ex command pastes the contents of a register after a specified line.
"add
How it works When you delete text in Vim with commands like dd, dw, or x, the deleted text goes into the unnamed register and the numbered registers (1-9).
"ayy "byy "cyy
How it works Vim provides 26 named registers (a through z) that you can use as independent clipboards.
:let @a=getline('.')<CR>@a
How it works Instead of recording keystrokes interactively, you can write a sequence of Vim commands as plain text in your buffer and then execute that text as
qa<C-r>=expression<CR>q
How it works The expression register (=) lets you evaluate Vimscript expressions and insert the result.