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.

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 command-sets, to get to edit mode press esc, to get to insert press i or ins

Command Explanation Mode
h j k l Moves the cursor left up down right respectively
i Changes to insert mode edit
esc Changes to edit mode insert
x Delete edit
dd delete a whole line edit
J Joins lines of text edit
i Changes to insert mode edit
esc:number RGoes to line number. Replace number with the number of the line you want.
ctrl+g Tells you the number of lines in a document and the line you are currently at
esc :q! Quit NOT saving changes Any
esc :w Writes file to disk Any
esc :wq Writes changes then exits Any

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


Back Home