SESSION 9		EDITING FILES


1. Adding text to a file:

Edit one of your files by typing as before `vi filename'. Move the cursor 
to the end of a line. Using `i' would allow insertion of text BEFORE the 
position of the cursor. To APPEND text after the cursor postion, and hence 
on to the end of a line, type

			a

followed by whatever text you wish to enter.  Return to command mode by 
typing `Esc' as usual.
The vi commands `i' and `a' complement each other, the former allowing 
insertion before the cursor position, the latter after.


2. Deleting a character:

Place the cursor on the character to be deleted. Now type 

			x

and the character disappears. This editing is accomplished without entering 
insert mode.


3. Replacing a single character:

Place the cursor on the character to be replaced. Type

			r

followed by the character you wish to be inserted. Again we do not need to 
enterinsert mode.


4. Adding new lines:

Place the cursor anywhere on the line below where you wish the new line to 
appear. Now type

			O			(uppercase O)

vi opens a new line above the cursor.

Typing 

			o			(lowercase o)

creates a new line below the cursor.


5. Deleting a line:

Place the cursor anywhere in the line. Type

			dd

and the line will be deleted.


6. The undo command:

If you made a mistake in your last command, then it may be `undone' by typing

			u

This is useful for recovery from having deleted a line or character accidentally.



7. Many commands can be repeated by preceding them with a number.
   e.g. 5x  deletes 5 characters.



8. vi is a line editor. The basic object is the line. Remember that to 
   complete one line and start a new line, you must press return 
   (like carriage return on a typewriter). 
   Many vi commands affect whole lines.



9. Summary of vi commands:

	Esc			return to command mode
	i			enter insert mode, text before cursor position
	a			text appended after cursor position
	O			new line created above cursor
	o			new line created below cursor
	x			deletes the character on which the cursor lies
	r			replaces character by next character typed
	dd			deletes the line on which the cursor lies
	:wq			moves vi to the vi command line, writes (saves)
				the file to disk, then quits vi.
	:q!			moves vi to the vi command line, quits without
				saving file



10. Exercises:

	a) Create a file `leccourse' consisting of a list of the courses
	you are attending this term. Save the file and quit vi.
	b) Append a line at the end of `leccourse' stating the total number 
	of lectures involved.
	c) Delete a line (by mistake) and undo the mistake.
	d) Insert at the beginning of each line the code (Ph221 etc) for each 
	course of `leccourse'.


END OF SESSION 9					file: edfil9
