Repeat a substitution with its flags
:&&
Example
Normal mode on line 1. Lines 1 and 2 both contain old old.
old old
old oldCursor on line 1, column 1- :s/old/new/g<CR> Line 1 · new new; g replaces every match
- j Line 2 · still old old
- :&&<CR> Repeat with g · line 2 becomes new new
new new
new newDetails & Vim help
Repeat the previous substitution on the current line while retaining its flags.
Carry a tested replacement to another line without retyping it.
Normal-mode & and :& drop the previous flags; :&& keeps them. An intervening search does not replace the stored substitute pattern. Avoid replaying c or other flags unintentionally.
Run :s/old/new/g on line 1, move to line 2, then use :&& to keep the g flag.
Try it in Vim
- Run :s/old/new/g on the first line.
- Move to the second line and run :&&.
- Use :%&& to repeat across the whole buffer when appropriate.