Really Quick Vi Guide

A lot of people including myself find vi difficult and yes I could tell you to use any other editor. However VI is on every linux, and unix I have ever used so knowing the basics is quicker than installing emacs/pico/nano/joe/whatever on every computer you every workstation you ever get on.

Some good misconceptions and arguments for VI here

Someone sent me a joke so I thought I would post it emacs is a great operating system shame it dosnt have a text editor!

I guess the most confusing thing about vi to the new user is that you cant just load a file up and start typing you have to switch modes. Also very annoying is the way older versions of vi use the keys HJKL for movement rather than the arrow keys (yes I realise this is because old terminal systems didnt have arrow keys).

Vi has serval modes the most important to you are edit and insert. Each mode has different commandsets, to get to edit mode press esc, to get to insert press i or ins

h j k lMoves the cursor left up down righ respectivly
iChanges to insert modeedit
escChanges to edit modeinsert
dddelete a whole lineedit
JJoins lines of textedit
iChanges to insert modeedit
esc:numberGoes to line number. Replace number with the number of the line you want.
ctrl+gTells you the number of lines in a document and the line you are currently at
esc :q!Quit NOT saving changesAny
esc :wWrites file to diskAny
esc :wqWrites changes then exitsAny

Search and Replace

To search press "/" then type the string you wish to find. Pressing "/" again with no arguement will reapeat the search

To replace text ":s/text to find/text to replace/g" that will replace the test on one line. To search and replace in the entire document use ":%s/text to find/text to replace/g".

There are loads of other commands and all sorts of scripting you can play with but these are the most common, and have served me well writing many of these web pages.

To get help in Vi type esc :help