Introduction
vi pronounced as ” vee eye ” is a unix editor available on almost all the unix operating systems , solaris , bsd ,aix , hpux etc.
This document is a quick reference to vi editor and will be of help if your are new to unix , learning unix or just refreshing your vi knowledge after a few years.

Requirements:
In order to work correctly the vi need correct terminal type (TERM) setting .The TERM setting depends on the type of terminal you have . Commonly used TERM types are vt100 , vt220 and ansi . In most cases vt100 will work fine . In case vi is not able to understand the TERM you have given, it starts in open mode giving you a line by line display .
Generally TERM is taken from .profile or /etc/profile but can be set at the command line as :
$TERM=vt100
$export TERM

echo $TERM will display the current TERM set.

Create new file or Open existing file in vi
vi without any file name will open a new file where you can enter the text and edit but while coming out you will be asked to enter a valid file name to save the text. vi with a file name as argument will open that file for editing if the file already exists it opens it otherwise it creates a new file by the argument.
Example : $vi testfile
Creates or opens the existing file called testfile

Modes in vi

vi operates in following two modes :
i. ) Command Mode : After a file is opened it is opened in command
mode ,that is , input from the keyboard will be treated as vi commands
and you will not see the words you are typing on the screen .

ii.) Insert Mode: To enter the text you have to put vi in insert by pressing ‘i’ or ‘a’ after which you can add the text and whatever is being type will be seen on the screen. . To switch between these mode Esc key is used . Esc i
(text mode) Esc (command mode)

Saving & Exiting vi editor
You can exit vi in different ways :

1.) Quit without saving : If you don’t want to save the work :q will take you out without saving your editing in vi.2.) Write & quit : . Simple :w saves the current file but don’t exit. For save and quit :wq is used in vi.3.) Forced Quite : An ! (Exclamation sign at the end of exit commands ( :q! , :wq! ) causes a forced quit from vi after ignoring editing (for :q!) or writing (for :wq!) all the change

q will exit, but does not exit if there are changes.
q! will exit with unsaved changes.
wq will save and exit.
—
Looks like a good reference, but there are a few errors:

20d does not delete line 20, it deletes 20 lines.
:20d deletes line 20.

This command will replace the character 1 after the cursor with everything after the first keystroke:
s///g .
This command will perform a search and replace on the current line:
:s///g
This command will perform a search and replace on the entire document:
:%s///g

For simplicity (when working with searches involving slashes) I use the modified syntax:
:%s!!!g