How do I prepend text to every selected line even with uneven indentation?
:'<,'>normal! I//
Visual Block insert (I.
:'<,'>normal! I//
Visual Block insert (I.
:'>,'<normal @q
Running a macro over a range usually goes top to bottom, but that can break when the macro inserts or deletes lines.
macros #macros #ex-commands #visual-mode #normal-mode #refactoring
:'[,']normal! =
When you need to run a command on exactly the text you just changed, yanked, or pasted, Vim's automatic marks are faster and safer than reselecting manually.
command-line #command-line #marks #indentation #ex-commands #normal-mode
/\v<(TODO|FIXME|BUG)>
When you triage code, jumping among TODO, FIXME, and BUG markers quickly is often more useful than searching each token separately.
5g;
Most users know g; moves backward through the changelist, but fewer people use a count with it.
:lockmarks normal! >>
When you run editing commands from the command line, Vim usually updates special marks like '[ and '] to the changed text.
*Ndgn
When you are reviewing repetitive text, you often need to remove one specific match without running a broad substitute.
:g/./t.\<CR>
The :global command can apply an Ex action to every line that matches a pattern.
@='A;<Esc>'<CR>
Recorded macros are powerful, but sometimes you need a quick ephemeral sequence and do not want to occupy a register.
:debug normal @q
Recorded macros are powerful, but when one keystroke goes wrong they can fail fast and leave confusing state behind.
"=strftime('%F')<CR>p
The expression register lets you compute text on demand and insert it without leaving Normal mode workflows.
registers #registers #expression-register #normal-mode #automation
:set nrformats-=octal<CR>
By default, Vim may treat numbers with leading zeros as octal when you use and for increment/decrement.
:keeppatterns normal! @q<CR>
When you replay macros from Ex commands, Vim can overwrite @/ (the last search pattern) depending on what the macro does.
:normal! @q
Recorded macros can become fragile when your config defines mappings that shadow built-in keys.
]m / [m
When you're reviewing or refactoring C-style code, jumping by words or paragraphs is too coarse, and search can become noisy.
navigation #navigation #motions #code-navigation #normal-mode
:while search('TODO') | normal! @q | endwhile
A fixed count like 100@q is brittle: sometimes your macro needs 12 passes, sometimes 300, and over-running can corrupt already-processed text.
macros #macros #automation #search #normal-mode #ex-commands
gN
Most users know gn for selecting the next search match, but its counterpart gN is the real power move when you need to work backward through matches.
visual-mode #visual-mode #search #motions #editing #normal-mode
:windo normal! @q
When you split a file into multiple windows or keep several related buffers visible, repeating the same small cleanup in each one can be tedious.
macros #macros #windows #normal-mode #ex-commands #automation
*NgUgn
gn is often treated as a visual selection command, but it is more powerful when used as a motion target for operators.
qagUiwWq2@a
Macros are most powerful when they encode both the edit and the movement to the next target.