|This manual is designed to familiarizes
users with some of the commonly used vi commands. Please follow all the
instructions. Perhaps the most important thing about this editor is to
remember that vi has two modes; 1) Input mode : invoked
by pressing I, and it is used when you want to type, and 2) Command
mode : invoked by pressing Esc, and it is used to do other
things, except typing, for instance; moving up-down, left-right, deleting
characters, words, lines, saving, exiting, etc.
Note: In this manual, the words following a % symbol and written in boldface, for eg. % vi, are to be typed out ( without the % symbol). The words written in regular font following the % symbol and boldfaced commands are to be substituted by filename names in your system .
Step (1) : Opening vi:
At the prompt type % vi and press Enter, a blank screen will appear. A blank vi page will open in the command mode.
Step (2) : Typing a text, saving it, and exiting vi
2-1) Type the following 4 lines of text exactly the way it is shown below. To start typing press i to enter the Input mode, and type the following text.
"Depends on the size of the machine, a UNIX mashine can support
from one to handred users. Each user can run different set of programs.
Since a UNIX machine can support several users at the same time,
the cost of computer per usr is much les. "
2-2) Lets save it in the file text1;To save what you have typed press : Esc to go to command mode, then type: :wq text1 and press Enter(don't forget the : before the w) you are back at the command prompt again, %
2-3) To open file text1 again type : % vi text1
2-4) To leave the file without making any change, press Esc, then type : :q! (don't forget the : and the !)
Step (3) : Editing a file, save the changes, and exit vi
3-1) To open the file in vi, at the command prompt type :% vi text1
3-2) To find a word in the text, for instance mashine, type : :/mashine (don't forget the : and the /)
3-3) Moving on a letter and replacing it with another one : use arrow to move on the letter s in the word mashine, press r (replace) and press c.
3-4) To go to a particular line for instance line 2 type : :2 (don't forget : before 2)
3-5) Delete a character and type a new one in its place : move on the letter a in handred, press x to delete a, press I to switch to input mode, type u, press Esc to switch to the command mode.
3-6) Move to the end of the file : press Shift and G
3-7) Use arrow to move the cursor to the beginning of the word usr
Note: in the command mode, letters i, j, k, and i can be used for navigating up, down, left, and right.
|3-8) To delete the word usr press
(this will delete the word in front of cursor)
3-9) Press I and type the word user, then press Esc to switch to command mode
3-10) To append s after the word les, move to s and press a (append), and type the missing s, press Esc.
3-11) save the file and exit : :wq (remember the : before w)
Congratulations. You just finished the basics of what you need to know to work with vi editor. The following is a list of some more vi commands.