My original 'vi' document was written for the support staff in BTnet, it was aimed at the Solaris version of 'vi' but should suit most versions (in fact, everything except 'set showmode' should work) - This version was turned into HTML by Graham Lewis ( who had the misfortune to have to make sure people still knew how to use editors and things after I left.

With thanks to Michael Lawrie.

Some people are employed for what they know about networks
Some people are employed for what they do to a network
Michael was employed for what he might know, and might do to your network if he wasn't employed by you.

So - Michael's bluffers guide to "vi" version 1.0.a

If you sit down, digest this, and take note of everything in it, then you should be able to use vi just abut as well as anyone. It is not intended as a complete reference, it is just a reference that should be complete for most people's needs.

The very basic:

You start vi with: vi filename

The concepts.

vi has three modes - edit mode, insert mode and command mode. Commands in vi are case sensitive, so "h" is different from "H"

Edit mode

When you load vi, you will be in edit mode - You can move around the screen with the cursor keys, or, if they screw up (as they do over some links and on some terminals) you can use:

Also, if you put a number in front of the command, it will do it that number of times, so to go down 250 lines, try "250j"

To move around quickly:

To go to a numbered (eg, 40) line, try: "40G"

To search for some text, use "/" - Searching is case sensitive so, to search for say, "Teapot" you would type:


If you were not sure of the case, and wanted to match "teapot" as well, you could either do another search with "/teapot" or use a regular expression:


Searching works from the current cursor position downwards, if you want to repeat the last search, simply press "n".

Ok, so now we can move around, we may as well do something - first, deleting.

To replace the current character with something else, use "r" so, if your cursor was over a "+" sign, and you wanted to change it to a "-" sign, simply type "r-".

To replace the current word with something else, use "cw" (change word) type in the new word and hit ESCAPE (control-[ on some terminals) to go back into Edit-Mode. So, if your cursor was at the start of the word "tree" and you wanted to change it to "shop" type "cwshop"

The rest of the commands in this section take us into Insert-Mode, again, to exit from Insert-Mode to Edit-Mode, simply press Escape.

Cutting, copying and pasting is a bit more complicated, but you get used to it eventually. Basically, you either delete a block of text with "dd" (delete line(s)) or, yank it with "Y" and then paste it back with "p" or "P" ... Sooooo...

Finally, a couple more useful ones:

Command mode:

To get into command mode, press ":" from edit mode. When you hit RETURN at the end of the command, it will return you to edit mode.

The easiest way to show these is to just give examples:

:set showmode

This is useful, it shows you at the bottom right hand corner of the screen what mode you are in.


Quit from the current session, saving nothing.

:w hello.txt

Save the current file as "hello.txt".

:r /tmp/textfile.txt

Inserts the contents of the file "/tmp/textfile.txt" after the current line.


Replaces the first occurence of the word "michael" with "fred" in every line in the file.


Replaces the first occurence of the word "Michael" or "michael" with "Fred" in every line in the file.


As above, but this will replace every occurence, even if there is more than one on a line.


(Have I lost you yet?) - Replaces every occurence of "/tmp/teapot" with "/tmp/coffeepot" throughout the file. Basically the "\" before the "/"'s indicate that the character following the "\" is a special character, and shouldn't be interpreted as part of the command.

There you go - You are now a "vi" expert.

© 1997 Michael Lawrie