Solaris Advanced User's Guide

Changing Text

Changing text involves the substitution of one section of text for another. vi has several ways to do this, depending on circumstances.

Changing a Word

To replace a word, position the cursor at the beginning of the word to be replaced. Type cw, followed by the new word. To finish, press Esc.

To change part of a word, place the cursor on the word, to the right of the portion to be saved. Type cw, type the correction, and press Esc.

Changing a Line

To replace a line, position the cursor anywhere on the line and type cc. The line disappears, leaving a blank line for your new text (which can be of any length). Press Esc to finish.

Substituting Character(s)

To substitute one or more characters for the character under the cursor, type s, followed by the new text. Press Esc to return to command mode.

Replacing One Character

Use this command to replace the character highlighted by the cursor with another character. Position the cursor over the character and type r, followed by just one replacement character. After the substitution, vi automatically returns to command mode (you do not need to press Esc).