If you can see this check that

next section prev section up prev page next page

Replace and Substitute

Within vi you can replace a single character, substitute a single character with one or more characters, and substitute a different word for an existing word. For example, to replace a single characters in command mode, we can place the cursor under the character c in the word ants. So a line:


The circus has many ants.

Will be changed by typing 'rc' (replace with 'c') to:

The circus has many acts.

To substitute a single character with one or more characters, we can place the cursor under the character i in the word 'in' as follows:

My salary is one hundred pounds.

Will be changed by typing 'swa' ESC (substitute with 'wa') to:

My salary was one hundred pounds.

Notice when you type the s command a dollar sign $ appears in the place of the character. To substitute several characters you can precede the command with the number of characters you want to substitute as follows:

My salary is one million pounds.

Will be changed by typing '2stri' ESC (substitute two characters with 'tri') to:

My salary is one trillion pounds.

To change a word, you can use the cw (change word) command, while in command mode, as follows:

My salary is one hundred pounds.

Will be changed by typing 'cwthousand' ESC to:

My salary is one thousand pounds.

To substitute several words you could do the following:

Change four words in this line

Will be changed by typing '4cwEdit' ESC to:

Edit this line.

cc new words
Replace all characters in a line
C new words
Replace remaining characters in the line from cursor

Tutlinks: intro1 intro2 wildcard permission pipe vi essential admin net fwall DNS diag Apache1 Apache2 MySQL1 MySQL2
Useful: Quiz Forums
Site Links:XMLZoo ActiveSQL ProgZoo SQLZoo