Vim Recall繁體中文

Repeat a replacement across the buffer with the last search pattern

g&

Example

Normal 0 / 1
new old
old old
Cursor on line 2, column 1

Repeat a replacement across the buffer with the last search pattern.

Vim registers

/ Last search register
Characterwiseold
· space ⇥ tab ↵ line break
Before & after
Before
new old
old old
Cursor on line 2, column 1

Vim registers

/ Last search register
Characterwiseold
· space ⇥ tab ↵ line break
After
new new
new old
Cursor on line 2, column 1

Vim registers

/ Last search register
Characterwiseold
· space ⇥ tab ↵ line break

Start in Normal mode. A prior :s/old/new/ replaced the first old on line 1, establishing old as the previous pattern and new as the previous replacement. The cursor then moved to line 2 before this repeat.

Details & Vim help

Example replayed in Vim

g& replaces matches across the buffer using the last search pattern, the previous substitution’s replacement, and its flags. It is equivalent to :%s//~/&.