vi Hints and Tips for Beginners

Versions/variants of vi

vi is available on just about every UNIX system you will ever encounter, but it is a somewhat primitive editor. Newer and more capable variants exist, and in fact vi on the classroom/lab machines starts one of them -- vim ("vi improved"). It has many features not found in standard vi, including online help and optional syntax coloring. Start it with one of the following commands: An interactive tutorial can be started by typing vimtutor from the command line.

Modes in vi

vi, unlike many editors, has two distinct "modes", and what happens when you press keys depends on which mode you are in. The modes are: Several commands put you into insert mode -- i, a, etc. The version of vi installed on the CS lab machines displays INSERT at the bottom of the screen if you are in insert mode. To get out of insert mode, press the ESC key.

If you try to type commands while in insert mode, the commands will just be entered in your file. Press the ESC key, delete the commands from your file, and try the commands again.

If you try to enter text while not in insert mode, the text will be interpreted as commands, often with surprising results. If this happens, first get out of insert mode if necessary and then use the "undo" command (u) repeatedly to clean up.

Useful commands

This is a list of the more basic standard vi commands. In the following: In typing a command, do not include the square brackets used to denote optional text. We assume you've started the editor with vi myfile.

Possibly-confusing vim behaviors

vim has many features that while useful can also be sources of confusing. Here are some that are frequently encountered: