Flags and the Replacement Side

Flags

FlagDoes
gevery match on the line, not just the first
cconfirm each one
iignore case for this substitute
ncount matches without changing anything

:%s/pattern//gn is a quick “how many of these are there?” — it reports a count and changes nothing.

The confirm prompt

With c, each match offers y (yes), n (no), a (all the rest), q (quit), l (this one, then stop).

Backreferences

:%s/"\(\w\+\)":/"\U\1\E":/g
  • \(...\) captures, \1\9 reuse it
  • \U upper-cases everything after it, \L lower-cases, \E ends the change
  • & in the replacement means “the whole match”

Computed replacements

Prefix the replacement with \= and Vim evaluates it as an expression:

:%s/\d\+/\=submatch(0)*2/g      " double every number

Delimiters

The / is not special — any character works. When the pattern contains slashes, use something else:

:%s#/usr/local#/opt#g

Repeating

:s with no arguments repeats the last substitute on the current line. :%s//new/g reuses the last search pattern, so you can search first, confirm the matches highlight what you expect, then substitute.