So far, we've been working in edit mode. In this mode, we can move around the file with impunity, deleting or replacing existing text without worry. To add text, we have to switch to the insert mode. Fortunately, this isn't hard: Just move the cursor to the spot in the document you want to edit, hit I, and begin typing.
The first thing you should know is that vi takes the insert command rather literally. Wherever your cursor is when you hit I will be the first point at which you can begin typing. So if you're looking at a sentence like this:
w means to overwrite the last version
and the cursor is on the v in "overwrite," you're going to start inserting text where the v used to be. So if you try to type the words "saved file" you'll end up with a sentence that looks like this:
w means to osaved fileverwrite the last version
The easiest way around it is to position the cursor where you want it before you start typing. So, if I wanted to insert the phrase "saved file" after the word last, I would hit Escape to make sure I'm out of insert mode, move the cursor to the space between "last" and "version," hit I for insert, and type in a space and then "saved file."
Note: You cannot move around using the h, j, k, and l keys, or edit anything, while you're in insert mode! To snap out of insert mode and back into edit mode, hit the Escape key. Any time I'm in vi and forget which mode I'm in (it can happen), I hit Escape before I do anything else.
next page»