Computing Facilities
Electrical and Computer Engineering
Northwestern University

CFS Home | FAQs | Policies | PC Software | ECE Home | Search

Emacs Text Editing for Beginners

The emacs program is a product of the Free Software Foundation's GNU project. The name emacs stands for Editing MACroS. Emacs has everything you could ever want from a text editor and more. Much more.

Editing with emacs is very easy. Type

emacs FILENAME
to begin editing a file named FILENAME. If the file doesn't yet exist, it will be created. You can move your cursor using the movement commands, edit a new file using the file commands and exit Emacs using C-x C-c (hold down the Control key while you type an x followed by a c). By default, emacs will make a backup file (named FILENAME~) just in case you need to revert to the version of the file before you began editing it.

Movement Commands

Keystrokes Action
Right Arrow or C-f forward character
Left Arrow or C-b back character
   
Down Arrow or C-n next line
Up Arrow or C-p previous line
   
Page Up or C-v page up
Page Down or M-v page down (M is ESC)

File Commands

Keystrokes Action
C-x C-f find file
C-x C-s save current file, but do not quit
C-x C-c quit; you will be asked to save changes

The best way to learn more about Emacs is to use its on-line tutorial. The tutorial is quite comprehensive and will take 30-45 minutes to go through. You can start the tutorial by typing C-h t. If this does not work (as it might be the case where C-h is bound to delete) try

M-x help-with-tutorial
(hit the ESC key, release it, then hit x, and then type help-with-tutorial).

You can also use

Keystrokes Action
C-h a command appropose
C-h c describe key briefly
C-h f describe function
C-h w where is
C-h b describe bindings
C-h m describe mode

Or type

M-x list-options

to explore Emacs on your own. All of the Emacs documentation is online and can be browsed using C-h i.

Emacs can be customized to your needs by creating a ~/.emacs file. You can put your own key bindings and defaults in this file. Users familiar with the Lisp language will find the syntax familiar. Some common things that people put in their .emacs are:

;; goto a specific line
(global-set-key "\C-x\C-g" 'goto-line)

;; make searches case insensitive
(setq case-fold-search t)

;; always use fill mode
(setq-default auto-fill-function 'do-auto-fill)

Emacs is quite clever about the type of file you are editing. It will swicth into C-mode when editing .c or .h files; switch into lisp-mode for .lisp or .lsp files; tex- and latex-mode for .tex files; and fortan-mode for .f files. It will automatically indent lines according to mode, making your programming easier. Each mode also has its own set of bindings and variables that can help you interact with other programs.

2145 Sheridan Road . Evanston / IL . 60208
Phone: 847-491-8140 . FAX: 847-491-4455
webmaster@ece.northwestern.edu

Copyright © 2003 Northwestern University § All rights reserved § Fri Oct 24 14:20:40 CDT 2003