Office of Information Technology
Home

Calendar

Map
Home
Computing

Library

Search

Editing With Emacs

Emacs is a screen editor in the public domain. It is usable with virtually any type of keyboard because it depends exclusively on control sequences as editing commands, and therefore needs no special function or editing keys. Emacs also allows you a great deal of flexibility in customizing your editing sessions to your own needs, binding control sequences to keys, and so forth. It includes a number of modes as well, each useful for a different language or function.

Currently, UMBC is offering emacs in version 20.4.1, with several extensions originating locally. Every effort has been made to maintain a consistent interface across the wide variety of machines at UMBC; however, in view of hardware and software limitations, some systems are lacking certain emacs functions. Nevertheless, the features common to all systems should make emacs a powerful and valuable tool to Unix users.

Getting Started

To get started in emacs, you should follow its built-in tutorial, which covers all the fundamental emacs operations and points you toward help in learning advanced features. Invoke the editor by entering emacs at the system prompt. To access the tutorial, type the sequence <CTRL/h t>. This is a standard control sequence, followed by the character t. (Note that emacs uses C-h to depict the sequence in its associated documentation, and continues this format throughout. Therefore, in regard to emacs usage only, control sequences and similar notations will be shown in this alternative form in subsequent references.) You may go through the tutorial interactively, you may save your tutorial session in a file for subsequent printing, or you may do both. In order to save the file, however, you must make at least one change, such as inserting a blank space or a blank line. Then type C-x C-c. You will be asked if you wish to save the file. Respond y and the file TUTORIAL will be written to your default directory.

Some Special Things To Note

The tutorial often refers to a meta key, or to a key labeled edit. If you are using an SGI workstation, the alt key functions as meta.

Note that while esc appears on different places on different hardware, C-[ is always equivalent to esc and can be used in its place. Therefore, esc-a gives the same result as C-[ a. Also, note that holding down esc can cause emacs to send multiple escape characters, and thus go into a special mode. To abort this, enter C-g. In general, C-g is a very useful command to know, since the many possibilities that emacs offers can be confusing, and C-g will always bail you out of trouble.

There is an internal design conflict between emacs and certain systems with regard to the C-s and C-q sequences. All computers use C-s and C-q for flow control, to freeze and unfreeze the screen. Unfortunately, emacs uses C-s for the isearch-forward (incremental search) function, which conflicts with the hardware's operation.

If you type C-s and your screen freezes, then your system is interpreting this sequence as a terminal control signal. To unfreeze the screen, type C-q.

All of the emacs programs at UMBC have been modified so that C-\ performs C-s and C-^ performs C-q. As a result, any time you need to use C-s in emacs, you can type C-\ instead. This is also true for C-q. Type C-^ instead, provided, that is, that your keyboard is capable of C-^. If it isn't, you will have to use the extended command facility within emacs to perform commands that are bound to C-q. Fortunately, C-q is a rarely used command, so this is only a minor problem at worst. Finally, be sure to remember that under Unix, only one version of a file with a given name can exist in the same directory. Thus if you edit an existing file and write it to disk, the older version of the file will be deleted. If you believe you may need both, it is safest to copy the old file under another name before invoking the editor.

Getting Help

All of the on-line emacs help functions begin with the sequence C-h. Some of the help features (and their associated keystrokes) are:

    C-h

    Shows help on the help facility. Enter a question mark or another C-h for a range of help options, including those below.

    C-h c

    Follow with a command character or sequence. Shows help on the command you enter.

    C-h k

    Follow with a command character or sequence. Similar to C-h c, but gives more information, which is shown in an emacs window. To delete the window, use C-x 1.

    C-h t

    Starts the emacs on-line tutorial.

To leave help and resume your editing, the command is C-G. Comprehensive emacs documentation is available in the OIT technical library. Inquire at Print Dispatch, ECS 019.

Some Essential Keystrokes

See the end of this chapter for access to the the emacs Reference Card, a summary of emacs commands and their functions. Below is a subset of some of the most frequently used functions.

    C-a

    Move to beginning of line

    C-e

    Move to end of line

    C-v

    Move down one screen

    M-v

    Move up one screen

    M-<

    Move to beginning of file

    M->

    Move to end of file

    C-k

    Delete from cursor to end of line

    C-x C-s

    Save current file without leaving emacs

    C-x i

    Import a file---you will be prompted for file name

    C-x C-c

    Leave emacs---you will be prompted to save file

    C-@

    "Select" command; used for cut/paste to start selection process

    C-w

    "Cut" command; removes previously selected text

    C-y

    "Paste" command; inserts selected and cut text

C-s

          "Search" command; find text entered
M-x replace-str           "Replace"  command; replace existing text with new text

Recovering From A System Crash

Should you be in the midst of an editing session when a system crash occurs, emacs provides a means of recovering the work you had been doing. Invoke the editor, and then use the meta-x command followed by the name of the file you had been editing when the crash occurred. To illustrate, if you are editing markets at the time of a system failure, at your next login type emacs, and once inside the editor, enter meta-x markets to have your edited file restored.

Xemacs---A Version for X-Windows

Xemacs is a version of emacs designed for X-Windows. It provides the functionality of emacs with the ease of use of pull-down menus. Regular emacs will also run in an X-Window.

Emacs Reference Card

Use the URL http://www.geek-girl.com/emacs/refcard.html for access to the emacs Reference Card, a summary of useful emacs commands and their functions. Once you have experience with the on-line tutorial, this information should serve as a ready reference for future use.

Other useful URLS for emacs are at

GNU Emacs Reference Manual and Emacs Reference Materials

Office of Information Technology • Main Office: ECS 125 • Phone: 410-455-3838 • Email: oit@umbc.edu