Center for Instructional and Research

Computing Activities * E520 CSE

University of Florida Gainesville, FL

Call the UF Computing Help Desk for

 assistance • (904) 392-HELP

• SUNCOM 622-HELP Page I of 2

GNU Emacs Reference Card[1]

The emacs editor is a powerful editor found on some Unix

systems. This handout is only a brief guide to using the

emacs editor.  This document was prepared by Bob Coldwell. 

It is a summary of two CIRCA handouts with possible

applications to people in PHY 6156.

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..

Starting and stopping emacs

To enter Emacs type the emacs command, possibly with  the

name of the file to be edited.

emacs [test.f] – or if you want it to run as a separate session

emacs [test.f] &

To suspend emacs type Ctrl-z

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

Some emacs functions will not work correctly on terminals

in CIRCA public labs. 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.

The emacs installed on the CIRCA system has some Ctrl

keys remapped to new keys. In all cases while using emacs,

you should substitute the Ctrl characters as shown.

Use

Instead of

Ctrl-\

Ctrl-s

Ctrl-‘

Ctrl-q

Ctrl-/

Ctrl-

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     

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.

Marking

set mark here         C-@ or C-SPC

                               

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

C-w

From mark

M-w

Copies from mark

 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

quit current minibuffer

M-x compile

to enter emacs command

Files

read a file into Emacs                           C-x C-f

save a file back to disk        C-x C-s {C-x C-\}

insert contents of another file into this buffer C-x i

replace this file with the file you really want C-x C-v

write buffer to a specified file             C-x C-w

run Dired, the directory editor           C-x d

Getting Help

The Help system is simple. Type C-h and follow the directions. If you are a first-time user, type C-h t for a tutorial. (This card assumes you know the tutorial.)

get rid of Help window                        C-x 1

scroll Help window                              Esc ^

apropos: show commands matching a string C-h a

show the function a key runs            C-h e

describe a function                              C-h f

get mode-specific information           C-h m

Error Recovery

abort partially typed of executing command C-g

recover a file lost by a system crash   M-x recover-file

undo an unwanted change                                 C-x u or C-_

restore a buffer to its original contents  M-x revert-buffer

redraw garbaged screen                      C-l

Incremental Search

search forward                                      C-s {C-\}

search backward                                  C-r

regular expression search                   C-M-s {C-M-\}

Use C-s {C-\} or C-r again to repeat the search in either direction.

exit incremental search                        ESC

undo effect of last character              DEL

abort current search                            C-g

If Emacs is still searching, C-g will cancel the part of the search not done, otherwise it aborts the entire search.

 

Query Replace

interactively replace a text string       M-%

using regular expressions                   M-x query-replace-regexp

Valid responses in query-replace mode are

replace this one, go on to next           SPC

replace this one, don't move              ,

skip to next without replacing            DEL

replace all the remaining matches !

back up to the previous match          ^

exit query-replace                                 ESC

enter recursive edit (C-M-c to exit) C-r

Buffers     

select another buffer C-x b C-xb                       

list all buffers C-x C-b          C-x C-b                  

kill a buffer C-x k   C-xk                       

Spelling Check

check spelling of current word          M-$        

check spelling of all words in region M-x spell-region 

check spelling of entire buffer           M-x spell-buffer   

Shells      

execute a shell command                    M-!        

run a shell command on the region   M-1        

filter a region through a shell command C-u M-|            

start a shell in window *shell*          M-x shell               

Case Change

uppercase word    M-u

lowercase word    M-l

capitalize word      M-c

uppercase region C-x C-u

lowercase region  C-x C-l

capitalize region   M-x capitalize-region

 

 

 



[1] Copyrighl 1987 Free Software Foumfalion, Inc. Permissions on back. v 1.9