This document describes the basic commands for using emacs, a text editor on the Leland Systems (Cardinal, Tree, Power, Wisdom, and the Sweet Hall workstations).
Bare Essentials
Emacs displays a certain number of characters per line until it gets to the right margin of the display. Longer lines will wrap to the next physical line; this is indicated by a / at the end of each wrapped line. To avoid wrapping lines, either hit the Return key before you reach the right margin of the display, or choose the auto-fill option. (See the Formatting section.)
Note: The symbol "->" indicates that you press the Return key. Commands designated by C-<letter> are called Control commands. To execute Control commands, hold down the Control key while typing the letter indicated. Commands designated by ESC
Starting emacs:
host> emacs FILENAME ->
Exiting emacs:
| C-x C-c | system prompts for file save before exiting |
Editing:
| arrow keys | cursor movement keys |
| C-b, C-f | back, forward |
| C-p, C-n | up one line, down one line (for use if the keyboard arrow keys do not operate correctly) |
| DEL | delete previous character |
| host> man emacs -> | About emacs |
| C-h t | Emacs tutorial |
To learn about the many sophisticated features of emacs you can buy Richard Stallman's GNUemacs manual at the Stanford Bookstore.
Getting Help
You can invoke the general emacs help files by typing C-h C-h and following the instructions at the bottom of the screen.
| C-h a FUNCTION | lists commands related to FUNCTION |
| C-h F FUNCTION | get help about the specified function |
| C-x 1 | get rid of Help window |
| ESC C-v | scroll Help window forward |
| C-h i | display advanced emacs information browser |
For more information, contact a consultant at 725-2101.
Error Recovery
| C-g | cancel partially typed or accidental command |
| C-l | redraw garbaged screen |
| C-x u | undo the last major change |
| C-x b -> | if you accidentally get into the tutorial, this returns you to the default buffer |
| ESC x recover file | recover lost file |
| ESC x revert buffer | restore buffer to original contents |
| ESC x switch to buffer | re-enter buffer |
| C-v | scroll to next screen |
| ESC v | scroll to previous screen |
| Backward | Forward | |
| C-b | C-f | character |
| ESC b | ESC f | word |
| C-p | C-n | line |
| C-a | C-e | line beginning (or end) |
| ESC a | ESC e | sentence beginning (or end) |
| ESC [ | ESC ] | paragraph beginning (or end) |
| ESC < | ESC > | top of file (or end) |
| C-x b | select another buffer |
| C-x C-b | list all buffers |
| C-x 1 | get rid of buffer list |
| C-x k | kill a buffer |
| C-x 0 | dismiss this window |
| C-x 1 | dismiss all other windows |
| C-x 2 | split window in two horizontally |
| C-x 4 b | select a buffer in other window |
| C-x o | switch cursor to other window |
| C-x s | save the file |
| C-x C-w | save a file with a new name |
| C-x C-v | read a different file into emacs, replacing the current buffer |
| C-x C-f | read a different file into emacs, put it into another buffer |
| C-x i | insert contents of another file into this buffer |
| Backward | Forward | |
| DEL | C-d | character |
| ESC DEL | ESC d | kill word |
| ESC 0 C-k | C-k | kill line (to beginning/end) |
| C-x DEL | ESC k | kill sentence |
To move or copy a region of text in emacs, you must first "mark" it, then kill or copy the marked text, move the cursor to the desired location, and restore the killed or copied text. A region of text is defined by marking one end of it, then moving the cursor to the other end.
| C-@ | set mark here (or ESC _) |
| C-x C-x | exchange cursor and mark (used to verify you have marked the desired region) |
| ESC h | mark current paragraph |
| C-x C-p | mark current page |
| C-x h | mark entire buffer |
| C-w | kill the marked region |
| ESC w | copy the marked region |
All killed text (except single characters deleted with DEL or C-d) can be restored to the buffer. The most recently killed text is the first to be restored, then previously killed text blocks are restored in reverse order.
| C-y | restore last text to be killed |
| ESC y | replace that restored text with previously killed text. Repeated use will cycle through killed text blocks in reverse order, and must always follow either the original C-y or another ESC y. |
| C-x u | undo the last major change. |
| C-s | incremental search forward. |
| C-r | incremental search backward |
| ESC x search f -> STRING -> | alternative search forward command (see note above); use C-x Esc -> for next occurrences. |
| ESC % -> OLD STRING -> NEW STRING -> |
query before replacing each OLD STRING with NEW STRING. Respond y to replace this one, go to next; n to skip to next without replacing; ? for help. |
| ESC x replace s -> OLD STRING -> NEW STRING -> |
replace all occurrences of OLD STRING with NEW STRING |
| ESC q | reformat current paragraph |
| ESC g | reformat marked region |
| C-x u | undo the last major change |
| C-l | redraw screen, moving the line with the cursor to the center |
| ESC x auto fill | automatically wrap lines at the 76 character mark. Doing this command again turns off word wrap |
| C-u # C-x f | change wrap mark from 76 to # |
The last two commands set the format and must be followed by one of the first two in order to apply it to a particular section of text.
If you have an .emacs file in your directory, you may already have auto-fill (i.e. word-wrap) enabled. If you don't have an emacs file, you can get one by copying /usr/skel/.emacs into your home directory from any Sweet Hall workstation.
Replace NAME with the name of the printer (e.g., sweet0) and FILENAME with the name of the file you want to print.
To print on your own printer, you must first download the file to your desktop computer. Exactly how you do this depends on which communication package you use, as well as which type of computer you have. For more information, call Sweet Hall Consulting at 725-2101.
This document is based on originals prepared by Lynn Gale and Patrick Goebel of the Center for Advanced Study in the Behavioral Sciences.
Printing
When you're logged in on the Leland Systems you can print files on a Sweet Hall printer by typing the following command:
Copyright ©, 1995, by The Board of Trustees of the Leland Stanford Junior University. Permission granted to copy for non-commercial purposes, provided we receive acknowledgment and a copy of the document in which our material appears. No right is granted to quote from or use any material in this document for purposes of promoting any product or service.
RITS Publications
Document revised: January 1995