Search and replace in vi / vim

Linux

vi search and replace: (in command mode)

The following strings illustrate how to perform a search and replace in the Unix vi editor.

:g/old_text/s//new_text/g

Replace EOL (end of line)

:g/$/s//new_string/g

where $ is EOL and \t = a tab

The start of line can be equally easily searched and replaced – using the carat ^ symbol.

:g/^/s//new_string/g