Editing files on cattell or mail.sas

Once you have logged in, you might find it necessary or convenient to use some kind of text editing programs for creating and modifying files, writing mail, posting news articles, etc. Cattell offers four text editors: emacs, vi, pico, an nedit.

Emacs. Our emacs is the Gnu Emacs, a version of the diverse emacs family (which includes versions for Windows). It is an extensible, customizable, full-screen display editor. You can get a reference card. Here is a good little manual. Here is a complete manual. And here is a printable reference card. For further information, see the FAQ.

To edit a file using emacs, say:

emacs filename

emacs will create the file "filename" if it does not exist, or else bring the contents of the file into its buffer for editing. If you do not specify a filename, emacs will create a temporary file (empty) and let you input and edit the text. Enter text by typing just as you would at a typewriter. When you are done, exit emacs by typing ctrl-x ctrl-c. Depending on your previous actions, emacs will either prompt you to save the changes or save the file, and then exit.

Emacs lets you use the cursor keys to move around, and other movements or actions are accessed via keystrokes. To distinguish between keystrokes intended as addition to the text and keystrokes to issue a command, emacs uses special keys for commands. Some command use the ctrl key on the keyboard. This key should be held down while other keys are pressed. It is abbreviated with ^ in the commands listed below. The other key is the ESC key, which is pressed and lifted BEFORE the other keys. (In most versions of Emacs, now, with most terminals, you can use the Alt key - held down - instead of the ESC key before the other character in a command.)

Emacs always saves the original file, before changes, with the name of that file followed by a ~. You can remove this file with the command rm *~, which can be aliased to some command in .cshrc, such as rme.

Emacs has a on-line tutorial that you can use to learn how to edit or find out what a certain sequence of keystrokes or command represents. To use this tutorial, enter emacs, then type ^h (ctrl-h). ^h puts you in the help menu of emacs, T gets you the tutorial information).

The most useful emacs command is ^g, which undoes the mistaken command you just gave.

Below is a list of some of the most widely used command sequences in emacs.

Key SequenceCommand

 ^X^C exits emacs
 ^X^S saves (writes out) a file
 ^X^V visit another file without exiting emacs
 ^X i insert a file
 ^X u undo last change
 ^A go to the beginning of the line
 ^B backward one space (can also be achieved by using arrow keys)
 ^D delete a character
 ^E go to the end of the line
 ^F forward one space (can also be achieved by using arrow keys)
 ^G exits previous command sequence
 ^H help
 ^J symbol for end of line (see ^Q below)
 ^K kill the rest of the line
 ^L refresh the screen
 ^N next line (can also be achieved by using arrow keys)
 ^P previous line (can also be achieved by using arrow keys)
 ^Q quote the next character (useful for putting ^J in search)
    treats three-digit numbers as octal ascii codes
 ^R incremental search backward
 ^S incremental search forward (end with "enter" key)
 ^S enter - ordinary search (type enter before the string)  
 ^V next page
 ^W cut away everything between the last mark and here
 ^Y yank back what you just killed, copied, or cut
 ^Z temporarily suspend emacs
 ^@ set mark
 ESC-d delete a word
 ESC-q fill paragraph
 ESC-v previous page
 ESC-% search-replace (enter after each string)
 ESC-< go to the beginning of the file
 ESC-> go to the end of the file
 ESC-! shell escape

These are just some of the most common emacs commands. It is an extremely powerful program that can also be customized. Here is more information about emacs commands. And here is a complete manual.

Emacs reads the file ".emacs" when it starts up. You can change this file to customize your emacs environment. ".emacs" is written in the LISP programming language.


Pico is another text editor that is quite easy to use because the commands are listed at the bottom of the screen. The disadvantage of pico is that the commands listed at the bottom of the screen are all the commands there are. Otherwise you use pico just like emacs, pico [filename].


Nedit is an editor that works in the X window system, so you can use it from a terminal or something that simulates a terminal. It is highly recommended and self-splanatory. Like Word, it has a graphical user interface that is transparent and easy to learn. It is also available for Windows. Just type nedit to try it on Cattell.


vi is a much older editor than emacs, but it is still widely used. It has two modes, an editing mode and a text-entry mode. An advantage of this is that, when you are in the editing mode, the commands do not require special keys. Many tutorials and reference cards are available on the web.


Other editors:
There are many other editors for many different platforms (types of computers). One that comes with Windows, called "Notepad", used to be considered the worst of the lot, but recent versions of it are quite a bit improved. Here is a list of others.

Nedit (X Windows, and Windows - highly recommended by many people, and available on Cattell)
WinEdt
NTemacs (emacs for Win95 and up, free)
TextPad32
Alpha
JED (free)
Ultraedit
NoteTab
Super Note Tab (free)
Programmer's File Editor (PFE)
Vedit (high end, more expensive)
EditPad
Elvis (vi for windows)
Vim (improved vi for any platform)


Comments to baron@psych.upenn.edu