vi - The UNIX Editor

vi is the standard UNIX text editor. Even though there may be other editors available on the system that are easier to use and learn, vi is good to learn for several reasons. One reason was already mentioned: it is the UNIX standard. It is available on all UNIX systems. Also, once you become accustomed to vi, you will find that it is very powerful.

How to start up vi
There are several ways to get into the A editor. A few are listed below. These are to be typed at a UNIX prompt.
viEdit a new file (the file has no name yet)
vi fileedit file (where file is a file name)
vi -r fileEdit last saved version of file after a system or editor crash

Once you are in vi, you will need to know about its various modes.

vi Modes
There are four basic modes in vi:
command mode the default mode; allows you to enter vi commands
insert mode this mode allows you to insert text
edit mode this mode allows you to use line editing commands
shell escape mode this mode allows you to execute UNIX commands
You will only have to worry about the first two modes. As mentioned above, the command mode allows you to enter vi commands and the insert mode allows you to enter text. Once you are in insert mode, A commands will no longer work. They will only work within command mode. To return to command mode, hit ESC (the escape key). If you are unsure as to what mode you are in, hitting escape several times will ensure your return to command mode. Commands to get you into insert mode are listed below and labeled as such.

Basic vi commands (Note: aft commands are case sensitive)

Cursor movement
arrow keysto move up, down, left, and right (these work most times
k, j, h, Ito move up, down, left, and right respectively (these work times)
$move to the end of the line
0move to beginning of the line
ctrl-u, ctrl-dscroll up, down half a screen
ctrl-f, ctrl-bscroll up, down a full screen

Insert
All of the following commands put you in Insert Mode. To exit Insert Mode, hit ESC.
i insert text at cursor location
aappend text to the right of the cursor
Aappend text to the end of the current line
o,0start a new line above, below the current line

Delete
dd delete the current line
x delete the character at the cursor

Undo
u undo the last command

Search
/ Search forward for search string
? Search backward for search string

For example, if you wanted to search for the word "Monday," you would type:

/Monday
or
?Monday

depending on which direction you wanted to search in. Please note that searching is case sensitive.

Misc.
ctrl-I Refresh the screen

Saving and Exiting
:wsave file with current file name (if no name exists you will have to use the next command)
:w file save the file using file for the name
:wq save file and exit vi
:q exit vi (you may be prompted if changes have been made since last save)
:q! exit vi without saving any changes since the last save

There is more...
Remember, these are not all the commands vi has to offer. There are many more. However, they should be plenty to get started.








Last Updated: Wednesday, February 02, 2000 08:50:17

Univesity of Kentucky Home Page UK SLIS Home Page University of Kentucky Home Page UK School of Library and Library and Information Science