The purpose of this lesson is to introduce you to the many choices available in text editing and introduce you to the vi editor.
Since the earliest days of computers, people have encoded information in some way in order for a computer to understand it. People used paper tape with holes, punch cards, and casette tapes. Today, we use a keyboard. We type and store information on the computer. For many tasks in Unix and other work, plain text is all we need. So we need just a plain text editor. Not a word processor, not a page editing system, but just a plain text editor.
There are hundreds and hundreds of software programs that give you the ability to create and edit plain text files.
You just need to pick the one right for you and become excellent at using it.
The vi skills I learned more than 17 years ago have taken me through employment as a software engineer, three graduate degrees, and my present work in Web publishing. During all this time, I have known graduate students and co-workers who rejected vi and instead use a trendy, editor-of-the-moment. I have just quietly kept on using vi. I've never had to learn another editor, and I do not intend learn another. I even use Lemmy so that I can edit files in Windows using a vi editor clone.
The Unix command vi starts up the visual editor. The vi editor is one of the most common plain text editors available on nearly every Unix system. While many claim that vi is not easy to use at first, vi nonetheless is readily available and widely supported.
I will provide instruction here in vi. You will not have vi commands on the test, so you don't have to memorize vi. If you don't use vi for your work, you are responsible for choosing your own plain text editor and becoming adept at using it.
You start a vi editor session to edit a file called filename.txt like this:
$ vi filename.txt
When you issue this command, the appearance of your screen will change. Rather than seeing the shell prompt and the previous lines of the Unix commands and output, the entire Unix window or screen will appear to be the contents of the file filename.txt. If filename.txt was blank, or hadn't existed before you invoked the vi command, the screen will appear mostly blank.
This is the visual representation of a file you are editing. You use the keyboard as your interface to enter text or enter commands to manipulate that text.
The key thing to remember is that vi has two modes: command, and insert.
When you are in command mode, everything you type on the keyboard gets interpreted by vi as a command.
When you are in edit mode, most everything you type on the keyboard gets interpreted as characters and will appear in your file--letters, numbers, punctuation, line returns, etc.
When you are in insert mode, you can switch to command mode by pressing the Esc key on your keyboard (this is often at the left and upper portion of your keyboard).
When you are in command mode, there are many keys you can use to get into edit mode, each one gives you a slightly different way of starting to type your text. For example, if you are in command mode, you can simply type i on your keyboard to enter edit mode (i stands for insert). Then, the characters you type go into the file.
There are hundreds of vi commands; and it would take a fifteen week course to cover all the ways that you can use the vi editor to edit files, run commands, and do an astounding amount of things.
For a new user, this can be baffling and unnecessary. Instead, use this abbreviated set.
$ pico filename.txt
$ emacs filename.txt
If you know that you will never have to work in a Unix-only environment, you might be able to get along without knowing vi. For example, you might always work on a PC, with a Unix window available to run your Unix commands. If so, you might use a simple Windows-based plain text editor to create and edit files. For example, if you want to edit a file called apple.txt.
$ rm apple.txt
$ vi apple.txt
You could edit all your files using a PC-based text editor, then transfer files to your Unix account using a software package on your PC that supports file transfer protocol (FTP). You can find freeware and shareware ftp programs on hotfiles.com.
After installing ftp software on your PC, you would:
Experiment with a couple of the text editors available. If none of the Unix-based ones work well for you, figure out what does and how you can accomplish your assignments. Make sure the editor you choose edits and creates plain text and NOT word processor files, rich text files, Microsoft word or other files, or any other type of file other than plain text.
The bottom line is that you need to figure out what works best for you, then get good at it so that you can efficiently do your work.