Vim Recall繁體中文

Change the current or next match

cgn

Example

Normal 0 / 4
old blue old
Cursor on line 1, column 1

Replace a forward match of the last search pattern.

Vim registers

" Unnamed register
Characterwisesaved
- Small delete register
Characterwiseprior
· space ⇥ tab ↵ line break

Prepared search

Pattern
old
Before & after
Before
old blue old
Cursor on line 1, column 1

Vim registers

" Unnamed register
Characterwisesaved
- Small delete register
Characterwiseprior
· space ⇥ tab ↵ line break

Prepared search

Pattern
old
After
new blue old
Cursor on line 1, column 3

Vim registers

" Unnamed register Changed
Characterwiseold
- Small delete register Changed
Characterwiseold
· space ⇥ tab ↵ line break

Prepared search

Pattern
old

ILLUSTRATION. The last search pattern is old; the cursor is on its first match. Replacement text is new. Prepared characterwise registers contain saved in the unnamed register and prior in the small-delete (-) register. Changing this single-line match replaces both with old; typing the replacement preserves them.

Details & Vim help

Replace a forward match of the last search pattern.

c applies to gn, which selects the match under the cursor or searches forward. Type a replacement and Esc; dot can then repeat that match change. After a forward search, n visits the next match for review; it does not skip that match for a following dot. Advance to another match before repeating if you want to skip it. gn always searches forward, while n follows the last search direction; wrapscan controls wrapping.