We will be using pico in this class. If you are familiar with emacs or eager to learn a very popular and powerful Unix text editor, read on ...
There are many editors available for Unix systems, but this discussion will focus on the emacs text editing program because of its power, flexibility, extensibility, customizability, and prevalence. No matter where you get a Unix account, you are likely to have emacs at your disposal. Here is an index to the topics in this section:
Emacs uses control and escape characters to distinguish editor commands from
text to be inserted in the buffer. In this document, the notation "Control-X"
means to hold down the control key, and type the letter x. You don't need to
capitalize the x, or any other control character, by holding down the shift key.
"ESCAPE-X" means to press the escape key down, release it, and then type x.
Working with buffers
When you edit a file in emacs, you're not
really editing the file itself, as it sits out on a disk somewhere. Instead,
emacs makes a copy of the file, and stores the copy in a part of RAM memory
called a buffer. All the changes you make to the file are applied to the
buffer. When you save the file, emacs writes the contents of the buffer to the
disk.
Because the buffer exists in RAM memory, it disappears if the power is turned
off, or if the system crashes. Thus, you should use the save command often,
flushing your current buffer to disk. Once the file is on disk, a power outage
or system crash shouldn't harm it.
Basic operations in emacs
Here are some of the fundamental things
you'll need to do when you edit a document in emacs.
The command to save the contents of the buffer to a disk file is Control-X-Control-S. The save command overwrites the old version of the file. You may also write the contents of the buffer to a different file with the command Control-X-Control-W. Emacs will prompt you for the name of the file you want to create.
To create a new file, use Control-X-Control-F, just as if the file already existed. When emacs asks you for the file name, type in the name you want your new file to have, and emacs will create the file, and display an empty buffer for you to type in.
Emacs will perform file name completion for you. Type part of the name of the
file you want, and press the spacebar or tab key to get emacs to complete a file
name. If the partial name you've given matches more than one file, emacs will
display a list of all potential matches. You can continue typing in more of the
file's name, and pressing either file completion key, until you zero in on the
file you want.
Cursor motion
On well-configured systems, you will find that the
keyboard arrow keys will function correctly in emacs, moving you forward or
backward one character at a time, and up or down one line at a time. If the
arrow keys do not work, here's how to accomplish the same functions:
In addition to basic cursor motion, emacs provides some other handy cursor motion functions:
If you want to insert the contents of another file into the current buffer, place the cursor at the desired insertion point, and type Control-X-I. Emacs will ask you for the name of the file you wish to insert.
You may also insert text by cutting it from one place, and pasting it at the insertion point. See the next section for information on cutting and pasting.
Deleting text is easy. As you'd expect, the delete key deletes backward one character. Here are some other ways to delete text:
To define a region of text, place the cursor at one end of the region and press Control-spacebar. That sets the mark. Then, move the cursor to the other end of the region. The text between the mark and the cursor defines the region.
To cut a region of text, and place it in the kill buffer, use the command Control-W (think of Wipe).
The paste command is Control-Y. It Yanks the block of text from the kill buffer, and places it where the cursor rests. The Control-Y command only retrieves the most recently-cut block of text.
You can paste in earlier cuts by pressing ESCAPE-Y. The ESCAPE-Y command, used repeatedly, will take you back through several previous text blocks that were cut. The ESCAPE-Y command does not work unless you type Control-Y first.
You may copy a region of text into the kill buffer without cutting it. Define the text block by setting the mark at one end, and moving the cursor to the other end. Then type ESCAPE-W.
Many word processing programs can only undo the most recent command, but emacs remembers a long history of commands, allowing you to undo many changes by repeatedly entering the Control-_ code.
Customizing Emacs
The emacs editor is customizable in several ways.
You can set up your own key bindings, create your own macros, and even create
your own custom functions. Also, some aspects of the behavior of emacs is
controlled by variables that you can set.
You can learn more about emacs functions by invoking the online help facility (by typing ESC-X help) and then typing the "f" key to list functions. Pressing the space bar for completion will cause emacs to list all the built-in functions. A list of variables can be similarly obtained by invoking the online help, then typing "v" then the spacebar.
If you place variable settings, key bindings, and function declarations, in a text file called ".emacs" in your home directory, The emacs editor will load those definitions at startup time. Here is an emacs configuration file with some basic variable definitions and key bindings for you to peruse.