Information on emacs editor

Here is a list of commonly used key sequences and commands for emacs. This is only a short list, emacs has hundreds of commands. In the list, C-x means CTRL-x, M-x means ESC-x for any letter.


Meta Keys

C
C stands for the control key. So, interpret C-x as CTRL-x.
M
M stands for the ESC key. If ESC isn't recognized by your telnet connection, then C-[ will also create the M key. So, interpret M-x as ESC-x, or as C-[-x.

Back to Index


Help

C-h
Open the help window.
C-h t
Run the emacs tutorial.

Back to Index


Moving the cursor

C-v
Scroll forward in current buffer.
M-v
Scroll backward in current buffer.
M-f
Move forward one word.
M-b
Move backward one word.
C-a
Move to beginning of line.
C-e
Move to end of line.
M->
End of buffer.
M-<
<
Start of buffer.

Back to Index


Deleting text, Yanking Text, Regions

C-d
Delete current character.
DEL
Delete previous character.
M-DEL
Delete previous word.
M-d
Delete current word.
C-k
Delete line. Must do twice to remove end of line character, too.
C-w
Delete region. See setting mark.
M-w
Copy region to clipboard. See setting mark.
C-y
Paste the most recent delete or copy.
M-y
Paste previous delete or copy. Can be done repeatedly.
C-@ or C-SPACE
Set the mark for a copy, delete or other region command. To create a region, first set the mark, then move the cursor to the end of the region you want to create. With the cursor placed at the end of the region, issue the region altering command.
C-x C-x
Exchange mark and cursor.

Back to Index


Stopping commands and Undoing Edits

C-g
Abort current command.
C-x u
Undo last edit (can be done repeatedly).
M-x revert-buffer
Restore buffer to the state it was in when the file was last saved (or auto-saved).

Back to Index


Search

C-s
Incremental search forward. If C-s freezes your terminal, then use C-q to unfreeze it. You must use M-x isearch-forward if C-s freezes your screen.
C-r
Incremental search reverse.
ESC
Exit a successful search.

Back to Index


Search and Replace

M-%
Enter query-replace. Once in query-replace, the following 1-key commands can be given.

SPACE or Y
Once in query-replace: Replace and move to next instance.
DEL or N
Once inside query-replace: Do not replace and move to next instance.
!
Once inside query-replace: Replace all the rest and don't ask.
^
Once inside query-replace: Back up to previous instance.
ESC
Exit query-replace.

Back to Index


File commands

C-x C-f
You are prompted for the name of a file to open. You can specify an alternate directory in the path.
C-x C-s
Save the current file. If C-s freezes your screen, then use C-q to unfreeze it and use the command C-s to save all modified buffers.
C-x C-w
Write file, but prompt for file name.
C-x C-c
Save buffers and exit emacs.
C-z
Suspend emacs, return to shell.
C-x i
Include a file into the current buffer.
C-x k
Close the current buffer.
C-x b
Switch to the previous buffer.
C-x C-b
Open a window with a list of buffers. You can switch to this window and hit enter on any buffer to open it.

Back to Index


Windows

C-x o (letter o)
Switch to the other window (assuming that two are on the screen).
C-x 1
Close other window, leaving current one on entire screen.
C-x 0 (number 0)
Close current window, make other window full screen.

Back to Index


Editing and Compiling programs

M-x compile
Compile a program. This requires that you set up a makefile, or to type in the command to be used to compile the program. The advantage to this is that when you hit ENTER on an error in the compilation window, you are taken to that line and column in the source code. You can also just use C-x ` to visit each error in sequence. Very handy!
M-C-\
Indent a region. Select a region to indent, then do M-C-\. If you are in a major mode like C or Perl, then the region will be formatted according to the mode.
M-C-f
Move forward to the end of a balanced expression. Place the cursor on an opening {, (, or [ and the function will move the cursor after the balanced, closing }, ), or ].
M-C-b
Move backward to the start of a balanced expression. Place the cursor after a closing }, ), or ] and the function will move the cursor on the balanced, opening {, (, or [.  

Back to Index


Directory Editor

It is possible to view the contents of an entire directory with the DIRED command in emacs. Once in DIRED, you can open, rename, and delete files. It is also possible to navigate to other directories just by pressing ENTER on the directory name.

C-x d
Invoke the directory editor, DIRED. Once in DIRED, the following 1-letter commands can be used. Note that these commands are case sensitive.

d
Mark a file for deletion.
#
Mark all auto-save files for deletion.
~
Mark all backup files for deletion.
u
Undelete a file. This only unmarks a file, so it must be done before the x command is given.
x
Delete all marked files. Cannot be undeleted after this command.
R
Rename a file.
ENTER or e
Edit a file.
C
Copy a file.
M
Change mode of file.
Q
Do query-replace on a file. This is handy for modifying a makefile.

Back to Index