The vi editor

Okay, why on earth would anyone want to know how to use vi?

Well, although unix's tend to have lots of editors available, and virtually all of them are so much easier to use than vi, vi is the only screen editor garanteed to be on a system. Imagine this, you've just arrived someplace to start editing code, and your usualy editor (DopyEzEd) hasn't been installed on this new system, what do you do?

Do you

  1. Refuse to edit code and get fired.
  2. Waste a day finding the binaries for DopyEzEd that the system can run, or
  3. Use vi, which you learned on the off chance that you'd end up in this situation!
Well of course the third option is the best... especially if you don't get paid until the job's done!

Starting vi

To start editing a file in vi, you would type the command

vi [file-name(s)]

If the file exists you will get its contence displayed on the screen, otherwise you'll see an empty screen with lots of ~'s down the left hand side.

Quiting vi

The most important command you need to know at this point is how to leave vi without affecting the file you're editing in any way. Do this with :

:q![enter] (press the escape key, the ':' 'q' and '!' keys, then then press [enter])

Okay, let me explain a few things quickly... vi works in two modes, the first is command mode, where you can delete and manipulate text (cut n paste etc), this is the mode you start in. Then there is insert mode, where text typed is added to the file at the current cursor position. Actually there is a third mode, Ex mode, vi uses the unix command ex to do some interesting things, which someone might want to discuss in another tutorial?
To get from command mode to insert mode you press one of the following keys...

Once in insert mode you can move about the document with the cursor keys and continue inserting at various positions around the file. Don't count on this though, as it varies between vi's! Deleting should also work, but again this depends on your terminal, which you should try setting to VT100. To get back to command mode from insert mode, press ESCAPE, if that doesn't work try pressing ctrl-c, if _that_ doesn't work, yell for help!

Commands. (remember to press ESCAPE to get into command mode)

Quitting

You can try quitting with a [ESC]:q, which will not let you quit if you've made any alterations to the document.

Saving

Reading & status

Moving

You may find that the cursor keys dont work, so, while in command mode you can use the : keys to move about. Try changing your shell's terminal type with 'set term vt100' or TERM=vt100 before starting the vi editor which may activate cursor keys. Additionally:

Searching

Other commands.

The characters are deleted from the document and moved into a buffer from where they can be pasted using the p command. Be warned though that the buffer is deleted if you make virtually any other command!

Thats enough to get you going, there are many other commands available in vi, and if you happen to be running linux, DOS or have and Amiga, there is also a vi-clone called vim, which is an extended version of vi!

There is a tutor program for vi that you can install, it's called vilearn.tar.Z(compressed tar file)


I'd like to thank Lisa Jayne for the majority of this document
[Return to tutorial page] [Return to main page]
Page last updated by John-Lucas Brown 03-Apr-1997