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

Centos 7 intro: Paths | BasicShell | Search
Linux tutorials: intro1 intro2 wildcard permission pipe vi essential admin net SELinux1 SELinux2 fwall DNS diag Apache1 Apache2 log Mail
Caine 10.0: Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Mock Exam |
CPD: Cygwin | Paths | Files and head/tail | Find and regex | Sort | Log Analysis
Kali: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7a | 8a | 8b | 9 | 10 |
Kali 2020-4: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7 | 8a | 8b | 9 | 10 |
Useful: Quiz | Forums | Privacy Policy | Terms and Conditions

Linuxzoo created by Gordon Russell.
@ Copyright 2004-2023 Edinburgh Napier University