CS 136

Spring 2006
Williams College

Basic Emacs

Emacs is a widely used text editor for unix. It relies heavily upon control characters and meta characters as a means of entering editing commands. To enter a control character, you hold down the ctrl key and then type a letter. For example: C-x C-c means to hold down the ctrl key and press x then press c. To enter a meta character, you press the esc key (top left key on the keyboard) and then type a letter. For example: M-d means to press the esc key and then press d (and the next word will be deleted). In this case the escape key and the following key are typed separately. For example M-x represents typing the Escape key followed by the "x" key. To start emacs, type "emacs " in a shell window.

The last line of the emacs window is where command prompts and messages appear. The reverse video line immediately preceding it is a status line. It shows you the name of the file you are editing. Before that you should see -----. This means that the file is up-to-date. If it says, ---**, it means the buffer has been changed since it was last saved. If it says ---%%, it means that you cannot modify the file. After the filename is the "mode" that you are editing in. This should say "(Fundamental)", or "(Java)" when editing a Java file. Next is the current line number (L1 indicates the first line). Following that is an indication of how far the current line is in the file in terms of percentage. "All" indicates that the entire file is showing. "Top" indicates that you are on the first screenful. "Bottom" indicates that you are on the last screenful.

The area between the menu titles and the status line is the buffer that displays the contents of the file. Most of your typing goes directly into this buffer. Type some text. Notice the status line changes. You can move the cursor around using the arrow keys. Use the "C-x C-s" command to save the buffer to a file. Use "C-x C-c" to exit emacs. Here are the keyboard sequences for the most common Emacs commands:

 
C-v Next screenful
M-v Previous screenful
C-d Delete next character
Backspace Delete previous character
C-x C-s Save buffer to a file
C-x C-f Open a file
C-x C-c Exit Emacs
C-g Clear/cancel any command you are in
(accidentally or on purpose!)

You can find more Emacs commands in the Emacs Hints Page.