Exploring the vi modes

One of the hardest things to get used to when working with vi is its modal nature. There is the command mode that is used to enter new commands, and there is the insert mode (also referred to as input mode) that is used to enter text. Before being able to enter text, you need to enter insert mode first, because as its name suggests, command mode will just allow you to enter commands. Several methods are available for entering insert mode once vi is started:

• Use i to insert text at the current cursor position.

• Use a to append text after the current position of the cursor.

• Use o to open a new line under the current position of the cursor (my favorite option).

• Use O to open a new line above the current position of the cursor.

After entering insert mode, you can enter text, and vi will work just like any other editor. Now if you want to save your work, you should next return to command mode and use the appropriate commands to save your work. To return to command mode, press the Esc key.

Tip When starting vi, always give as an argument the name of the file you want to create with vi or the name of an existing file you would like to modify. If you don't do that, vi will display help text, and you will have to find out how to get out of this help text. Of course, you can always just read the entire help information to find out how that works.

Was this article helpful?

0 0

Post a comment