OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

Appending Text

vi has several different ways of entering insert mode. We have already used the i com- mand to insert text.

Let's go back to our foo.txt file for a moment:


The quick brown fox jumped over the lazy dog.

The quick brown fox jumped over the lazy dog.


If we wanted to add some text to the end of this sentence, we would discover that the i command will not do it, since we can't move the cursor beyond the end of the line. vi provides a command to append text, the sensibly named “a” command. If we move the cursor to the end of the line and type “a”, the cursor will move past the end of the line and vi will enter insert mode. This will allow us to add some more text:


The quick brown fox jumped over the lazy dog. It was cool.

The quick brown fox jumped over the lazy dog. It was cool.


Remember to press the Esc key to exit insert mode.

Since we will almost always want to append text to the end of a line, vi offers a shortcut to move to the end of the current line and start appending. It's the “A” command. Let's try it and add some more lines to our file.

First, we'll move the cursor to the beginning of the line using the “0” (zero) command.


The quick brown fox jumped over the lazy dog. It was cool.

Line 2

Line 3

Line 4

Line 5

The quick brown fox jumped over the lazy dog. It was cool.

Line 2

Line 3

Line 4

Line 5


Again, press the Esc key to exit insert mode.

As we can see, the “A” command is more useful as it moves the cursor to the end of the line before starting insert mode.


Top OS Cloud Computing at OnWorks: