NEXT UP Edit Mode
Next: Command Mode

Insert Mode

As edit mode uses so many of the ordinary keyboard letters as commands, when you actually want to insert some new text into the file, that you have to switch the editor into a new mode which will treat these characters as ordinary letters to add to the text. Afterwards, when you finish entering text, you need to be able to switch back to edit mode.

This is the purpose of insert mode. As you will see, there are many ways to enter insert mode for different purposes. However, whichever way you use to get into insert mode, there is only one way out - using the Esc key. Some keyboard types do not support an explicit escape key. In these cases the same function can always he achieved by using Ctrl-[.

The usual ways to get into insert mode, once you have positioned the cursor appropriately are:

iinsert text to the left of the current cursor position;
aappend text to the right of the current cursor position.

It may seem strange that both of these commands are required, but if either of them were missing it would make inserting in some situations more difficult.

You will often find that you want to add text starting on a new line. In these cases it is possible to move the cursor to the end of the line above the position where the new text will go, and then use the a command followed by pressing Enter or Return to open up a blank line to be filled with the new text. A simpler way to achieve this is to position the cursor anywhere on the line above the required position, then use the o command. This will open a blank line below the current cursor line and enter insert mode at the start of the blank line ready for the entry of text. The O command will do the same thing but will open the gap on the line before the current cursor line:

oopen a blank line below the current cursor line;
Oopen a blank line above the current cursor line.

Special versions of the insert and append commands can be used to move the cursor to the start of the current line or the end of the current line and enter insert mode there:

Iinsert at the start of the line;
Ainsert after the end of the line.

Text Substitution

In addition to the commands which just enter the insert mode, there are several commands which allow text substitution - effectively deleting a block of text before entering insert mode to accept the replacement text. The main commands for this are:

s substitute the current cursor character with new text;
cwchange the word to the right of the cursor for new text;
cbchange the word before the current cursor for new text;
cdchange the current cursor line for new text.

Putting a number before any of the commands in this block extends their function as follows:

nssubstitute next n characters with new text;
ncwchange n words to the right of the cursor;
ncbchange the n words before the current cursor;
ncdchange next n lines with new text.

In addition to the previous commands there are also two further change commands which can prove useful:

c$change characters to end of line for new text;
cOchange characters to start of line for new text.

NEXT UP previous
Next: Command Mode