Changing text involves substituting one section of text for another. vi has several ways to do this, depending on circumstances.
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, enter the correction, and press Esc.
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.
To replace part of a line, place the cursor to the right of the portion to be saved. Type C, enter the correction, and press Esc. This changes the portion of the line from the current cursor position to the end of the line.
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.
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 (there's no need to press Esc).
Correcting transposed characters takes just two keystrokes in vi. Suppose you find that you've typed "teh" when you meant to enter "the". Make the correction by putting the cursor over the first letter to be moved (in this case, e), and then type xp. The e and h will trade places - and vi will automatically return to command mode.
To break a line without affecting text, move the cursor to a space where you want the line to break and type r (for "replace") followed by Return. Note that if you type r with the cursor on a character and then press Return, that character will be replaced by the Return.
To join two lines, place the cursor on the upper line and type an uppercase J. (There's no need to press Esc after typing J.)