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.
1014 results for "i" a""
Use :let i=1 with macro
By combining a Vimscript variable with a macro, you can create sequences with incrementing numbers.
"ayi(
Combining named registers with text object motions lets you precisely yank structured content — like function arguments, quoted strings, or bracketed expressi
:let i=1 then use <C-r>=i<CR> in macro
By combining a Vimscript variable with the expression register inside a macro, you can create a counter that increments on each replay.
:let i=1\nqao<C-r>=i\n<Esc>:let i+=1\nq
Use a counter variable with the expression register inside a macro.
=i{
When editing code with messy indentation — after a paste, a merge conflict, or a refactor — you often need to fix just one block rather than the entire file
qaI// <Esc>jq
This macro adds a // comment prefix to the beginning of the current line and moves down.
<C-v>jjI1. <Esc>
Visual block insert can add numbered prefixes to lines.
[I
How it works The [I command searches the current file (and included files) for the word under the cursor and displays a list of all matching lines with their li
:let @a = ''
Registers persist their contents throughout your Vim session and even across sessions if viminfo or shada is enabled.
qaI1. <Esc>jq
Start at line 1, record a macro that inserts 1.
v + repeated iw/aw/i(/a(/ip/ap
Once you enter visual mode, you can progressively expand your selection by typing increasingly larger text objects.
visual-mode #visual-mode #text-objects #editing #selection #productivity
I
The I (uppercase) command moves the cursor to the first non-blank character of the current line and enters insert mode.
:%s/\<old\>/new/g
Wrapping your search pattern in \ word boundary anchors ensures that Vim only matches the exact whole word, preventing accidental replacements inside longer wor
:s/\d\+/\=submatch(0)+1/g
The \= prefix in a :substitute replacement field tells Vim to evaluate the following as a Vimscript expression rather than treating it as a literal string.
:reg a
The :reg a command shows the contents of register a, which reveals the keystrokes stored in the macro.
<C-o> / <C-i>
Vim maintains a jumplist — a history of every "jump" you make (searches, marks, gg, G, %, etc.
:'<,'>normal A;
The :normal command executes normal-mode keystrokes on every line in a range.
command-line #command-line #ex-commands #editing #normal-mode #batch-editing
V select then :norm A text
Selecting lines and running :norm A text appends the same text to the end of every selected line.
:let @a = "Iprefix: \<Esc>"
The :let @a = ".
q{a-z}...q
Recording a macro captures a sequence of keystrokes into a register, which you can replay later.