CIRCA Unix Services

This handout can be found online at:
http://www.circa.ufl.edu/handouts/unix/elmemacs.html

Using emacs on the CIRCA Unix system

August 23, 2005


Table of Contents

  1. The Emacs Editor
  2. Special Keys
  3. Starting and Stopping Emacs
  4. Online Tutorial
  5. Keyboard Usage in CIRCA Labs
  6. Commands to move the cursor
  7. Deleting or killing text
  8. Miscellaneous commands

The emacs editor

The emacs editor is a powerful editor found on some Unix systems. This handout is only a brief guide to using the emacs editor.

Special keys

Use the control key (Ctrl) in combination with another key to send a special control character to the computer. The control key is like a shift key that is held down while another key is pressed. For example, to type Ctrl-U, press and hold the Ctrl key and press the U key. In the emacs manual and emacs online information, C-x is used to mean Ctrl-x.

The Esc key sends a special character, called the escape character to the computer. If your terminal or workstation does not have an Esc key, or if the Esc key doesn't seem to work correctly, you can type Ctrl-[ to send the escape character.

Meta characters are unique to emacs. In this handout and in most Unix documentation, the use of a meta character is shown as M-x. This means that you must first type the meta key and then the x key. In most versions of emacs, the Esc key is used as the meta key. If you're using the CIRCA Unix system from a VT220 in E211 CSE, you can also use the F11 key as the meta key.

Starting and stopping emacs

To start the emacs editor, type the emacs command with the name of the file to be edited. For example, to edit the file test.f, type this command:

emacs test.f

To exit the editor and save the file you're working on, follow these steps:

  1. Type Ctrl-x, Ctrl-c.
  2. If you've made changes to the file, emacs will ask you whether you want to save the changes. Press the "y" or "n" key for either yes or no.
  3. If you type "n", emacs will ask you if you are sure you want to quit without saving the file. If you are sure, type "yes" and press Return.

Emacs has features and modes that you might accidentally activate by pressing the wrong key. If you find yourself stuck, try typing Ctrl-g.

Online tutorial

If you are a new emacs user, you may want to look at the online tutorial. Follow these steps:

  1. Enter the emacs command without a file name to start emacs.
  2. Type Ctrl-h and then press the "t" key.
  3. Follow the tutorial directions on the screen. To leave the tutorial, type Ctrl-g.

Keyboard usage in CIRCA labs

Depending on your environment, some emacs functions will not work correctly. In emacs, Ctrl-s is used to begin an incremental search for text, but on many terminals, this will freeze the computer display. To unfreeze the display, type Ctrl-q.

Commands to move the cursor

 Key          How cursor moves
 ------       ----------------------------
 Ctrl-b       left one character              
 Ctrl-f       right one character             
 Ctrl-n       down one line                   
 Ctrl-u       up one line                     
 M-b          back a word                     
 M-f          forward a word                  
 Ctrl-a       to the beginning of line        
 Ctrl-e       to the end of line              
 Ctrl-v       forward one screen              
 M-v          backward one screen             
 M-<          to the top of the buffer        
 M->          to the bottom of the buffer     

If your terminal or workstation has arrow keys and emacs has been properly configured, you may be able to use these keys to move the cursor left, right, up, and down.

Deleting or killing text

In emacs, text in your file can be deleted or killed. Deleted text is removed from the file. Killed text is also deleted but can be reinserted back into your file.

These commands delete text:

 Key        Delete what
 ------     ---------------------------
 DEL        character before the cursor       
 Ctrl-d     character at the cursor           
These commands kill text:

 Key       Kill what
 ------    --------------------------
 Ctrl-k    from cursor to end of line         
 M-d       to end of word                     
 M-DEL     previous word                      

To yank (restore) the text just killed, type Ctrl-y.

Miscellaneous commands

 Key       Function
 ------    ------------------------------------              
 Ctrl-o    insert blank line below current line                               
 Ctrl-/    undo last change                   
 Ctrl-g    abort current command            
 M-x       to enter emacs command             

Center for Instructional and Research Computing Activities • E520 CSE • University of Florida, Gainesville, FL
Call the UF Computing Help Desk for Assistance • (352) 392-HELP • SUNCOM 622-HELP