The vi cheat sheet


Who is this for?


Most editors today are visual and follow a standard format. They have a bar at the top of the window and (starting on the left) have a drop down menu for: File, Edit, View, and so on. If you've used one editor, you will likely be able to use another. You may have to learn the fancy features, but the basics are the same.

Long ago, and in a galaxy far, far away, there was a time when there was no de facto standard. There was no such thing as X-Windows, or Windows. The guys at Apple were still laboring in their garage. Many editors operated on one line at a time and you couldn't see the previous or next line.

Enter VI. VI was really hot stuff when it came out. You could edit a whole page at a time, it was extensible, there were lots of powerful commands, etc. But that was a long time ago, and much better editors have been released since then. So you'll never have to use VI, right? Ok, picture this: some Jurassic Park remnant comes dragging his knuckles down the corridor at your latest gig. You have to write some code post haste and you have to do it on some Unix system (Sun Solaris, HPUX, AIX, Linux?! Guess what? The only editor on this box is VI. Hey, maybe you even learned how to use Emacs and somehow skip the VI stage (like I did). Sooner or later, you are going to have to know how to do this.

Don't worry. VI is really easy to learn. I'm going to lay out all the basics for you, i.e., the bare minimum you need to know to get through a job. If you need to know more...well then you have my sympathies.

A little background

VI is short for "Visual editor" and is pronounce "vee-eye." It may be the first popular Unix editor that allowed the user to edit more than one line at a time.
VI has three modes. They are: "escape", "insert", and "line".
When you first start VI, you will be in escape mode.

The Cheat Sheet


Escape mode commands to go into insert mode:
aappend after the cursor
Aappend after the end of line
iinsert before the cursor
Iinsert at the beginning of the line
oopen a new line below the current line
Oopen a new line above the current line

Navigation keys
lspace forward
hspace backwards
jmove down one line
kmove up one line

To enter last line mode, type ":" then:
wwrite
qquit
q!I really want to quit.
wqsave changes and quit

A few more useful things
CTRL-Dpage down one page
CTRL-Upage up one page
uundo last editing command
Uundo all changes made to the current line
ffind next occurrence of a word
Ffind previous occurrence of a word


...my apologies to everyone who thinks VI is a great editor :-) 1