Vi Editor Find and Replace String – Ex Mode

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

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.


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


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