File Editing

 

  To alter and create files it is most convenient to use a text editor. UNIX has four built-in editors: vi, ex, ed and edit. There is also an optional editor, emacs, which the NRAO systems have. The ones used most often are vi and emacs, which are full-screen editors. The Suns come with edt (a commercial version has been purchased to help in the transition), but it is possible to set up your emacs initialization file, .emacs, so that your keypad will function almost exactly as it does under real EDT.

Editor: vi

The editor vi has two modes of operation: command mode and insert mode. In command mode you can move the cursor around the text, and make changes to existing text. To enter new text you must use insert mode. You can get into insert mode with the I or i (insert),A or a (append) and O or o (open line) commands. To exit from insert mode hit the ESC (escape) key; on some terminals the ESC key is the ctrl-[ (control key with the left square bracket).

To edit a file type vi followed by the filename. If you are creating a new file use the same format. To exit from vi type :wq or ZZ, e.g.

login% vi params

The screen will then clear and at the bottom of the screen there will be a status line, e.g.

params [new file]

There are two useful features of vi you should know about. First, if you execute a command you wish you hadn't, vi provides a command to undo the last change you made; just type u. The undo command only lets you reverse a single change. To restore a complete line type U; this will only work if you do not move off the line.

Second, if you are editing a file with vi and the system crashes, don't panic. The system will save the journal file. When the system comes back up you will be sent a mail message to tell you what file you were editing. You can recover your file by using vi -r <filename>.

Please note that in your .login and .cshrc files, which set up your environment, the first time you log on, there will already be some commands for setting up your terminal as a vt102. Since terminal setup can be extremely complicated in UNIX, don't remove what is already there unless you wish to set it up again yourself in some other way. Many screen-oriented programs, like vi, will not work properly if your terminal has not been set up. If you are using a VT220 or VT220 emulator, you should go to the General screen in Set-up and set your terminal to VT100 mode (VT220 ID is harmless with it).

To get a basic idea of how to run the editor type man vi . If you wish to see the many commands for vi , refer to Editing Text Files.

Editor: emacs

emacs is the supported editor of choice at NRAO. Unlike vi, emacs is not a modal editor. Special functions, as in EDT, are implemented with control keys, and any key not defined to execute a function will be inserted in the text. By default these control keys are not mapped to your keypad, but you can set this up if you wish. If you are really keen on EDT, you can even set up your keypad so that emacs looks almost exactly like it.

There are a few special functions of emacs you should know about. First, for those new to it, emacs has a tutorial mode which can greatly help you to learn your way around. The first time you invoke emacs, it will tell you how to run this (note: since this isn't mentioned until well into the tutorial -- you get out of emacs using ^X^C). Second, it has a much nicer undo function than vi. Third, it saves the previous version of the file by appending a ~ to the original filename, so if you do something silly you can still get this previous version back. And finally, it has a semi-automatic recovery for aborted editing sessions. If a related journal file exists which is newer than the file you invoke emacs on, it will inform you, and allow you to recover all the changes that were made during the aborted session.

Manuals are available on using emacs, although for many people the tutorial is enough to get them well on their way.

Spell

The command spell collects the words from a document and compares them to a spelling list. Words that do not match ones in the spelling file are printed on the standard output (the screen). The format for spell is:

login% spell <filename>

You may wish to have your misspelled words put in a file where you can look at them at any time. To do so, just redirect the output to a file by using the > sign, e.g.

login% spell letters > letters.err

This example will check the spelling in the file letters and put the misspelled words in the file letters.err. For more details, see the man page on spell

Ispell

The command ispell is a very useful spell-checking program which can be invoked from the % prompt or run directly from within emacs by typing ^CS. It runs interactively, prompting you for actions on words it does not recognize, and also has an interface from emacs so you can spell-check your file without exiting from emacs. It recognizes TeX formats, and uses a more comprehensive dictionary than spell. For more details, see the man page on ispell.

Last modified on [an error occurred while processing this directive]

Page maintained by Gayle Rhodes