Using the Search and Replace Routine

Finally we change the program back to a `Hello stedi' program through the search and replace command. This last method is perhaps the simplest method of the three. First we will investigate another mode for searching: the forward search. In forward search mode the search moves forward from the location of the cursor to the end of the file and does not return to the beginning of the file as in a circular search. So before the search begins, we will see that the cursor is placed earlier in the file than the word to be searched for by pressing the <Home> key.

Then we will be ready to use the search and replace command issued from the command line. The general formula for replacing one a string `string1' by another `string2' is the following:

/string1/=/string2/options
The word `options' indicates that certain options are allowed at the end of the command. For example, there is an associated `veto' option which tells the editor to pause after it has found the word in its search and ask whether the word should be replaced. You can set this option by adding a `v' or `V' at the end of the command. There is also the search mode option as mentioned for simple search commands. The forward search is indicated by the character `>'. To effect the desired search:

After executing this command, the cursor will position itself on the `W' of `World' and a query asking whether the word should be changed or not will appear in the command line. In answer to the query,

The editor will make the replacement and you have once again changed the word `World' to the word `stedi'.