There are three modes of operation in
vi. Understanding the function of these three modes is the key to
working with vi. All commands available with vi can be classified in
one of the three modes. Figure
lists the modes and a brief description of each. Figure
shows how to switch modes and get from one mode to another.
Command Mode
This is the initial mode for creating and editing files. When you
start the vi editor and open a file, you are in command mode.
In this mode, you can enter cursor positioning commands to move around
the file and editing commands to perform functions and modifications
of existing text. Command mode is the starting point for the
other modes. You can change to entry mode or last-line
mode from here. To move from entry mode to last-line mode or
vice versa, you must first switch back to command mode. All
commands are initiated from command mode.
The Escape key always puts you in
command mode. Use the Escape key if you are not sure what mode you are
in. When in doubt, press Esc to return to command mode before issuing
any other commands. While in command mode, you can move your cursor
around the text on the screen and do advanced editing commands.
Entry Mode
You must be in entry mode to enter text. To enter text, you must type
a vi insert command such as i (input), o (open new line),
or a (append). This takes vi out of command mode and puts
it into entry mode. In this mode, text will not be interpreted as
editing commands. When you finish entering text in your file, press
the Escape key to return to command mode.
Last-line Mode
From command mode, you can type a colon (:), which places you at
the bottom line of the screen. This is called last-line mode.
The changes made to a document are kept in a memory buffer until
written to the disk. From last-line mode, you can save your work
periodically by writing it to disk while remaining in vi or you can
save and quit vi. You can also quit vi without saving the changes. Last-line
mode can also be used to search for strings and to set preferences.
|