Vi Editor Find and Replace String – Ex Mode

How do I find and replace all string occurrences within entire text file using vim editor?

Answer
Vi editor is based on ex the original ex editor written back in 1976. One of the features inherited from this editor is a way simply search and replace any string withing either single line, first occurrences or in entire text. Here are few examples:
Replace a first occurrence of word vim for the word vi on the current line.

:s/vim/vi

Substitute first occurrence on each line of the word vim for the word vi

:g/vim/s//vi

Lastly, substitute every occurrence of the word vim for the word vim on all lines

:g/vim/s//vi/g