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

:%s/search_string/replacement_string/g

The % 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 continue searching for other occurrences of search_string . To confirm each replacement, add the confirm ( c ) flag after the global flag. via Indiana University

For example I just needed to replace all instances of GROUP with GROUP_ (to import schema from MS Access to MySQL database). Here is the command I used:

:%s/GROUP/GROUP_/g