Prelim 4 The vi Editor (some, not all)

The main editor, the thing we will use to create HTML files and Perl programs (which will themselves generate HTML files) in Unix systems is vi. This is a very cryptic editor, which is, like Unix, powerful, but silent. Remember, when you are frustrated, that people who developed these systems were working on teletypes, which were loud and noisy (and SLOW), so they tried to keep the typing (by humans) and the printing (by the computer and printer) to an absolute minimum.
The primodial editor, ed, was a line editor suited for typing terminals with hard output, i.e., teletypes. In this day and age, perhaps you have never seen a teletype, but these machines were ubiquitous once, tied to telegraphy, and were easily converted to use as I/O devices for computers.
With the advent of video terminals, line editing became, first and foremost, silent, i.e., output clatter was eliminated. Secondly, in the lovely silence, it became clear that one could see many lines of text at the same time using a CRT tube. Therefore, a full screen editor was developed, based on `ed', which allowed the programmer to see (usually) 24 lines of text at a time, allowed the programmer to place the cursor where ever s/he wanted on the screen, and allowed the programmer to change anything on the screen at will. This editor was `vi', and although there have been many others since then which have been introduced, `vi' is on all Unix systems, and therefore is the basic editor that you should learn.

Creating the HTML page, `home.html'


Just type
vi home.html
to see vi bring up the empty (since we are creating this file for the first time) text file known as `home.html'. Vi now sits there silently, offering no hint as to what to do next. Type
i <HEAD>This is some heading text</HEAD>
Follow this with a RETURN and then immediately type the single character ESCape which should be on your keyboard somewhere, or hold down the Control key and type the letter C (we will indicate that as ^C). (Simultaneously holding down the Control key and pressing a letter sends a different signal to the computer than just pressing the letter. In this case, ^C sends a control character to the computer which is, for our purposes, the equivalent of ESCape, which is also a control character.) Your screen should show what you typed.
Notice that the original `i' in the stuff you typed in, i.e., ``i<HEAD ../...'', has disappeared. This is truly vi'ish stuff. That `i' is a vi command ([i]nsert) which puts the computer into insert or input mode, so that everything typed from then on, until the ESC, is inserted into the file at the point where the cursor was before the `i' command was received. Wow.
Now type
ZZ
to file the program you just wrote. `ZZ' is a vi command which says `file this and then quit vi', and perhaps was chosen because it is onomatopoetic with going to sleep.
Type in
ls home.html Click here to review `ls'
to see that you have indeed created a file name home.html. To see even more information about this file, type
ls -l home.html Click here to review `ls-l'
which will show you a lot of stuff about this file (and others).

Creating the the rest of the HTML page, `home.html'

If you now, again, issue the command
vi home.html
you will see the file which you just typed into the computer re-appear. The `cursor' is located at the top left of your screen (behind and perhaps in front of) the `<' of the string `<HEAD>'.
If you now use the right arrow key, that cursor will move to the `H'. Repeated applications of the right arrow will move the cursor one character at a time over to the right.
Now type `^' to see the cursor move all the way to the left (front) of the line.
Now type `$' to see the cursor move all the way to the right (end) of the line.
Now type `i'. This will change you to input mode, and anything you type now will be placed in the file `home.html'. Type a RETURN (to start a new line) and then start typing in the text of the `home.html' page which we showed before. Click here to see the `home.html' page we are creating

Moving About the Error Plagued `home.html' File

After you have cursed and sworn, and somehow typed in some partial replicate of our `home.html' page, press Ctrl-C (^C) to exit the input mode.
Using your arrow keys, move the cursor about the file, watching how end of lines are handled. Vi is (for most novices) quite bizarre, and requires getting used to.
Anyway, now type `:' which puts us in command mode (and notice where the cursor went), and then type `1'. This will take you to line 1.
FOR SAFETY SAKE, PLEASE type `:w' now, to write a copy of what is on the screen into the file called `home.html', the file we are editing. This will save us from catastrophe if we make some mistake. It is a wise practice to periodically save you work this way!
Most likely, you have made some mistakes in entering the text. Using the arrow keys move the cursor to the first error, and then decide what you want to do. At this point, you should have enough facility to edit the file `home.html' (saving it occasionally (:w)) until it is approximately correct. Of course, the full power of the editor requires learning a lot more, but if you are willing to settle for limited editing power, you can proceed on to composing questions, which is why you are putting youself through this.

One last comment about `vi' and Unix in general. The backspace/delete keys are always peculiar, and you will have to experiment with your system to see what works for you. Most computer keyboards contain three options, a backspace key, a delete key, and Ctrl-h (^h). Sorry about that, only experimenting will tell you what works for you.

Finally, to exit the editor, you have several options.


Return to the last section (prelim2 - HOME.HTML -).
Return to the main book TOC.