Search & Replace Flags

Now that we have seen the basics of search and replace, lets take a look at some of the flags that can be used to modify the search and replace behavior.

Flag Description
g Replace all occurrences of the specified pattern in each line.
i Ignore case
I Don't ignore case
n Report the number of matches. Does not replace text.
c Confirm each substitution.


By default Vim will execute one substitution per line. When the g flag is present all matches in will be replaced in each line.

i and I

These override the configuration settings for ignorecase and smartcase for the current search and replacement.


Do not execute the substitution, but report the number of substitutions that would have been made. This can be useful as a dry-run before actually executing a replacement.


When the c flag is present, Vim will execute the search and replace, then ask you to confirm each replacement before committing it.

Response Description
y Accept the current substitution
l Accept the current substitution as the last substitution.
n Decline the current substitution and proceed to the next.
<Esc> Quit, declining any remaining unaccepted substitutions.
a Accept the current any remaining substitutions.
q Quit, declining any remaining substitutions.
CTRL-E Scroll the screen up
CTRL-Y Scroll the screen down