Vim tip 25: substitute flags
Here are some of the flags you can use with the substitute command:
g
replace all occurrences within a matching line- by default, only the first matching portion will be replaced
c
ask for confirmation before each replacementi
ignore case for searchpatternI
don't ignore case for searchpattern
These flags are applicable for the substitute command but not /
or ?
searches. Flags can also be combined, for example:
s/cat/Dog/gi
replace every occurrence ofcat
withDog
- Case is ignored, so
Cat
,cAt
,CAT
, etc are all valid matches - Note that
i
doesn't affect the case of the replacement string
- Case is ignored, so
See :h s_flags for a complete list of flags and more details about them.
Video demo:
See also my Vim Reference Guide and curated list of resources for Vim.