SESSION 8		VI EDITOR

*** This is a text editor which can be used on all UNIX systems without 
the requirement of a window. We will be using 'muemacs' so this and the 
following session may be omitted. You are at liberty to learn and use it 
if you wish. It can be very quick and efficient but is cryptic and not 
very user-friendly. ***


1. The syntax required to start the vi editor is

			vi  filename

Let us use vi to create a new file called "namadddob" which will contain 
your name, address, and date of birth. Enter the command

			vi namadddob

vi clears the screen, initialises each line with a tilde(~) and positions 
the cursor at the top left of the screen. The tildes (~) indicates 
nonexistent lines which we must distinguish from blank lines within a file.

The vi editor is now in COMMAND MODE awaiting instructions about what to do 
next. In command mode most keyboard keys represent editing commands. 


2. To insert text into the file, you must move vi from command mode to 
INSERT mode. To do this type

			i

but do NOT press return. You may now type text. The keys now mostly 
correspond to the characters indicated. Type 3 or 4 short lines.


3. To ESCAPE from insert mode press the escape (Esc) key. This returns you 
to command mode. This is an important key to remember. If you are in doubt 
about which mode you are in, Esc will ensure you are in command mode.


4. Next, press the colon key

			:

(but do not press return).
This will move the cursor to the bottom left hand corner of the screen, to 
the line called the vi COMMAND LINE. Now enter

			wq

followed by return. The w means `write to disk' and the q means `quit'. 
This command saves your file and then exits vi, returning control to the 
shell.

If you do not wish to save the file , instead of wq, type

			q!

If the file existed prior to this editing session, then it will remain 
unchanged.


5. To examine an existing file, say "hithere", type

			vi hithere

The cursor may be moved anywhere in the file using the arrow keys on the 
right hand side of your keyboard. Try them.

To insert text at a point in the file immediately before the cursor position, 
enter insert mode by typing i. Enter some letters. To return to command mode,
press Esc as before. This time, do not save these changes. Hence type

			:

to move to the vi command line followed by

			q!

Invoke vi again to check that no changes were made.


7. X Windows. Eventually it would be preferable to handle all of our 
activities using a windows environment so that a variety of activities 
may be undertaken simultaneously [e.g. a Unix command window to execute 
commands and run programs, a text editor window to read these SESSION 
files for example, a second text editor window to create a new file, and 
so on]. The text editor commands are then more easily and efficiently 
manipulated, the commands mostly being invoked using a mouse. However you 
may not always have access to a terminal supporting X-windows. Hence we 
study vi which is available on all Unix systems. 

8. Exercises:
	
	a) Create a 2 line file using vi and save it.
	b) Create a 2 line file using vi but do not save it.
	c) Do an `ls' to check a) and b).



END OF SESSION 8					file: vi8
