Confirm replacements throughout a file
:%s/old/new/gc
Example
Normal 0 / 5Command-line 1 / 5Awaiting confirmation 2 / 5Awaiting confirmation 3 / 5Awaiting confirmation 4 / 5Normal 5 / 5old old
oldCursor on line 1, column 1old old
oldCursor on line 1, column 1old old
oldCursor on line 1, column 1new old
oldCursor on line 1, column 5new old
oldCursor on line 2, column 1new old
oldCursor on line 2, column 1Ask before replacing each old match.
Type the concrete substitution command without submitting it yet.
Command line
- Input
:%s/old/new/gc
Submit the command and request confirmation at the first old match.
Substitution confirmation
- Command
:%s/old/new/gc- Current match
line 1, columns 1–3- Choices
y replace · n skip · a all · q quit · l last
Replace the first match and ask about the second.
Substitution confirmation
- Command
:%s/old/new/gc- Current match
line 1, columns 5–7- Choices
y replace · n skip · a all · q quit · l last
Skip the second match and ask about the third.
Substitution confirmation
- Command
:%s/old/new/gc- Current match
line 2, columns 1–3- Choices
y replace · n skip · a all · q quit · l last
Stop substitution; only the first match was changed.
Before & after
old old
oldCursor on line 1, column 1new old
oldCursor on line 2, column 1ILLUSTRATION. gdefault and edcompatible are off. Three old matches are prepared; answer y, n, then q.
Details & Vim help
Ask before replacing each old match.
With gdefault and edcompatible off, g considers all matches and c requests confirmation. Answer y to replace, n to skip, a for all remaining, q to quit, or l to replace this one and stop.