Vim Recall繁體中文

Repeat a substitution with its flags

:&&

Example

Normal mode on line 1. Lines 1 and 2 both contain old old.

Before
old old
old old
Cursor on line 1, column 1
  1. :s/old/new/g<CR> Line 1 · new new; g replaces every match
  2. j Line 2 · still old old
  3. :&&<CR> Repeat with g · line 2 becomes new new
After
new new
new new
Details & 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

  1. Run :s/old/new/g on the first line.
  2. Move to the second line and run :&&.
  3. Use :%&& to repeat across the whole buffer when appropriate.