:%s/search_string/replacement_string/g
Basic search and replace
The :substitute command searches for a text pattern, and replaces it with a text string. There are many options, but these are what you probably want:
:%s/foo/bar/g
Find each occurrence of 'foo', and replace it with 'bar'.
:%s/foo/bar/gc
Change each 'foo' to 'bar', but ask for confirmation first.
:%s/\<foo\>/bar/gc
Change only whole words exactly matching 'foo' to 'bar'; ask for confirmation.
:%s/foo/bar/gci
Change each 'foo' (case insensitive) to 'bar'; ask for confirmation.
This may be wanted after using :set noignorecase to make searches case sensitive (the default).
:%s/foo/bar/gcI
Change each 'foo' (case sensitive) to 'bar'; ask for confirmation.
This may be wanted after using :set ignorecase to make searches case insensitive.
The g flag means global – each occurrence in the line is changed, rather than just the first.
This command replaces every search_string on the current line with replacement_string. Omitting the g (global) flag at the end of the command will cause only the first occurrence ofsearch_string to be altered. Often you may wish to confirm each replacement. This can be done with the confirm flag c. The confirm flag should be placed after or in place of the g flag. Suppose I had the following line: