To find and replace one or more occurences of a given text pattern with a new text string, use the s[ubstitute] command.
First we need to do is to open the file we want to do the "search and replace"
qkim@lotta:~> vim file.txt
This is the content of file.txt. Lets change some of it with search and replace.
This is a test, a test this is. Just a lots of tests. I want to change test with beer.
:%s/test/beer/g
4 substitutions on 1 line
:wq
qkim@lotta:~> cat file.txt
This is the content of file.txt. Lets change some of it with search and replace.
This is a beer, a beer this is. Just a lots of beers. I want to change beer with beer.
Add comment