GTKC Knowledgebase
A little bit of wisdom
Search and replace in vi / vim
Posted by  Admin on


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


Tags: Vi , Vim , Text manipulation , Linux

Return to home page: Home