vi global replace

Question:
How to globally replace a search string in vi?

To perform a global search and replace in vi, use the 'search and replace' command:

:%s/search_string/replacement_string/g

The %s is a shortcut that tells vi to search all lines of the file for search_string and change it to replacement_string. The global (g) flag at the end of the command tells vi to replace all instances of the search_string.

If you wish to confirm each replacement, add the confirm (c) flag after the global flag.

If you are in insert mode in vi, hit the esc key to return to the command mode.  Afterwhich you'll be able to use the above search and replace command.