Archive for the tag 'substitute'

SBDavid

Search and substitute

Search and substitute

You can easily search for data in the buffer using the vim search command. To enter a search string, press the forward slash (/) key.

The substitute command allows you to quickly replace (substitute) one word for another in the text. To get to the substitute command you must be in command line mode.

The format for the substitute command is:

:s/old/new/

There are a few modifications you can make to the substitute command to substitute more than one occurrence of the text:

:s/old/new/g to replace all occurrences of old in a line
:#,#s/old/new/g to replace all occurrences of old between two line numbers

:%s/old/new/g to replace all occurrences of old in the entire file
:%s/old/new/gc to replace all occurrences of old in the entire file, but prompt for each occurrence.