Vi - UNIX editor Seminar - Rahman Tashakkori Department of Physics, Southern University and A&M College

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, and etc. Notice: on some systems, to execute vi the system must be able to emulate vt100. If you are experiencing a problem or you want to make sure that you are emulating vt100, follow step (0), otherwise go to step (1).

Step (0) : setting vt100

At the prompt type : setenv TERM vt100 (on some machines TERM=vt100)

Step (1) : Opening vi:

At the prompt type vi (grant% vi)

a blank screen will appear. A blank vi page will open in the command mode.

Step (2) : Typing a text, save it, and exit vi

2-1) We want to type the following 4 lines of text exactly the way it is shown below and save it in the file text1;

"Depends on the size of the machine, a UNIX mashine can support

form 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. "

To start typing press i to enter the Input mode, and type the above text.

2-2) To save what you have typed press : Esc to be in command mode

then type :wq text1 and press Enter

you are back at the command prompt again, grant%

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!

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) Find a word in the text, for instance mashine, type : :/mashine

3-3) Moving on a letter and replacing it with another one : use arrow to move on 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

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

3-8) To delete the word usr press dw (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

Congratulations. You just finished the basics of what you need to know to work with vi editor. Follow is the list of some more vi commands.

yy followed by p command (the yy command copies the current line and p command will paste it at as new line after the cursor)

yyn Yank n lines (default is 1) starting from the current

p Put line(s) you yanked right after the line where the cursor is

$ End of line

e End of the word to the right

o Open a line below the current line

O Open a line above the current line

x Delete the character

nx Delete the number of characters specified by n, starting with the current.

u Undo the change

ddn Delete the current line

) End of sentence

( Beginning of sentence

} End of paragraph

{ Beginning of paragraph

0 Beginning of line

A Add text at the end of the line

J Move down

H Move Right

K Move Up

L Move Left

rev : Aug. 22, 1998