Vim search and replace

09 Jul 2019

Ref

For all lines

find each occurrence of ‘<foo’ in all lines, and replace it with ‘bar’

  • Without confirmation
    • :%s/\<foo/bar/g
  • With confirmation
    • :s/\<foo/bar/g

For one line

  • Without confirmation
    • %s/foo/bar/g
  • With confirmation
    • %s/foo/bar/gc

Case sensitive

%s/foo/bar/gci

Case insensitive

$s/foo/bar/gcI