Vim Examples: Search and Replace

Last updated:
Table of Contents

WIP Alert This is a work in progress. Current information is correct but more content may be added in the future.

Hit ESC to enter COMMAND MODE

Search and Replace

Replace all instances of 'foo' with 'bar'.

:%s/foo/bar/g

Case-insensitive Search and Replace

Replace all instances of 'foo' (case-insensitive) with 'bar'.

:%s/foo/bar/gi

Search and replace with regex

You need to escape (, ) and |.

:%s/\(foo\|bar\)/QUUX/g

"foo bar baz" becomes "QUUX QUUX baz"

Dialogue & Discussion