Wartburg College
Linux Computation Lab

Useful Emacs Commands


[Cursor] [Files] [Help] [Editing] [Buffers] [Search] [Compiling] [Panic]

Emacs is a very powerful multi-windowing text editor. You can get a tutorial by typing <ctrl>-h t (control-h followed by a t) from the fire-up screen. If you are brand new to emacs, it would be worth your while to walk through it. In the commands below, the notation "C-" indicates a control character (hold down <Ctrl> and type the character), and "M-" indicates a meta-character. On most terminals, a meta character is obtained by prefixing the character with <Esc> (i.e. push and release the escape key before hitting the character). Some terminals may have an <Alt>, <Edit> or <Meta> key that works like a <shift> for typing meta-characters.

Cursor movement:

Some terminals may allow use of arrow keys, if not:
C-f
forward one char
C-b
backward one char
C-p
up to previous line
C-n
down to next line
C-a
beginning of line
C-e
end of line
C-v
scroll screen down
M-v
scroll screen up
M->
end of file
M-<
top of file
C-l
re-center screen on current line

File manipulation:

C-x C-f
Open or create a file
C-x C-v
Replace buffer with a different file
C-x i
Insert file at current cursor position
C-x C-s
Save buffer to file (This may hang your terminal, use
C-q
to restart it).
C-x s
Save all changed buffers.
C-x C-w
Write buffer to file (will prompt for file name).
C-x C-c
Save buffers and exit emacs
C-z
Suspend emacs (use "fg" to restart where you lef off)

Help commands:

C-h
Enter help system
C-h f
Get help for a given emacs command
C-h k
Get help for a certain keystroke sequence
M-x
"apropos" Find commands relevant to a key word.

Editing Commands:

<delete> or <backspace> Delete previous character
C-d
Delete the current character
C-k
Cut to the end of line into "clipboard"
C-<space>
to mark the beginning of a region.
C-w
Cut region between mark and cursor.
M-w
Copy region between mark and cursor to clipboard.
C-y
"yank" (paste) clipboard text back into buffer at cursor.
C-_ or C-x u
Undo previous edit (can go back multiple steps).

Buffer manipulation:

C-x 2
Split screen into two windows
C-x 1
Revert to one window
C-x o
Switch to other window
C-x b
Change buffer displayed in this window.
C-x k
Kill this buffer (close the file).

Searching:

C-s
Incremental search forward
C-r
Incremental search backward
<esc>
Exit a search
M-%
Search and replace

Compiling:

M-x
"Compile" Start a compilation. Emacs will prompt for a compiling command (suggesting "make -k"). Enter the appropriate command (i.e. "g++ -o myprogram myprogram.cpp")
C-x
Cycle through messages in the compile buffer. Emacs will show the line on which the error is reported in the editing buffer.

Universal panic:

C-g
Quit this comand!


This page is maintained by Dr. John Zelle. Send comments to: john.zelle@wartburg.edu