Basic Linux Tutorial
Computer Tutorial

Replacing Text



Replacing Text

In addition to inserting and deleting text, you can also replace existing text with new text. You can replace a single character or many lines of the text. The r command is used to replace a single character. When you press r while in command mode, nothing happens, but as soon as you press the next character, it appears on the screen replacing the character at the current cursor location. To replace one character and then go to insert mode, use the s command. You will see a $ symbol and vi will put you in the insert mode just after replacing the current character. You can also replace multiple characters with the R command.

Command Effect
r Replace current character remaining in command mode
s Replace current character and go to insert mode
R Replace multiple characters until the key is pressed
cw Change to the beginning of next word
cc Change entire line
cG Change to the end of file