Emacs Key Combinations

Taken from a page by Bernhard G. Bodmann at the University of Houston, with a few additions of my own.

Note that C-x means Control-X while M-x means Meta-X where meta may mean hitting and releasing the escape key, or alt. These keys are excerpted from the Unix in a Nutshell book. The first column has their default key binding; the second their function name; last is a short description.t is the syntax table for this buffer?

  1. File Handling Commands
C-x C-f find-file Find a file and read it to screen.
C-x C-v find-alternate-file Read a different file.
C-x i insert-file Insert a file at the cursors position.
C-x C-s save-buffer Save the current buffer.
C-x C-w write-file Write the contents of the buffer to a file.
C-x C-c save-buffers-kill-emacs Save all open buffers and get out of emacs.
C-z suspend-emacs Suspend emacs.

 

2.Cursor Movement Commands

C-f forward-char Move cursor one character.
C-b backward-char Move backward one character.
C-p previous-line Move up one line.
C-n next-line Move down one line.
M-f forward-word Move to the next word. (words are defined by whitespace/special characters.)
M-b backward-word Move to the previous word.
C-a beginning-of-line Move to the beginning of the line.
C-e end-of-line Move to the end of the line.
M-a backward-sentence Move back one sentence.
Esc-v scroll-down Scroll up one screen. (cursor goes up, but text goes down)
C-v scroll-up Scroll down one screen (cursor goes down, but text goes up)
C-x [ backward-page Go back one page.
C-x ] forward-page Go forward one page.
M-> end-of-buffer Move to end of buffer.
M-< beginning-of-buffer Move to beginning of the current buffer.
C-l recenter Redraw the screen with the current line in the center.
M-(a number) digit-argument Do the next command (a number) of times.

Some cheat sheets have “M-v” to scroll up. That has never worked for me. I use “Esc-v” to scroll up.

The scroll commands seem to do the opposite of what they are called. Here is an explanation from the Emacs documentation: In Emacs, scrolling up or down refers to the direction that the text moves in the window, not the direction that the window moves relative to the text. This terminology was adopted by Emacs before the modern meaning of “scrolling up” and “scrolling down” became widespread. Hence, the strange result that PageDown scrolls up in the Emacs sense.

3.Deletion Commands

Del backward-delete-char Delete the previous character.
C-d delete-char Delete the character under the cursor.
M-Del backward-kill-word Delete the previous word.
C-k kill-line Delete from the cursor to the end of line.
M-k kill-sentence Delete the sentence the cursor is in.
C-x Del backward-kill-sentence Delete the previous sentence.
C-y yank Restore deleted text at cursor.
C-w kill-region Delete a marked region.
backward-kill-paragraph Delete the previous paragraph.
kill-paragraph Delete from the cursor to the end of the paragraph.

4.Paragraphs and Regions

C-@ set-mark Mark the beginning (or end) of a region.
C-Space set-mark Ibid.
C-x C-p mark-page Mark the current page.
C-x C-x exchange-point-and-make Exchange the location of the cursor and the mark.
C-x h mark-whole-buffer Mark the current buffer.
M-q fill-paragraph Reset the paragraph.
M-g fill-region Reformat individual paragraphs with region.
M-h mark-paragraph Mark select paragraph.

 

5.Stopping and Undoing Commands

C-g keyboard-quit Stop current command Now!
C-x u advertised-undo Undo the last edit (do it often)
revert-buffer Return the buffer to the state when last autosaved.

 

6.Transposition Commands

C-t transpose-chars Transpose the two letters.
M-t transpose-words Switch two words.
C-x C-t transpose-lines Switch two lines.
transpose-sentences Switch two sentences.
transpose-paragraphs Switch two paragraphs.

7.Capitalization Commands

M-c capitalize-word Capitalize the first letter of the current word.
M-u upcase-word Make the word all uppercase.
M-l downcase-word Make the word all lowercase.
C-x C-l downcase-region Make the region all lowercase.
C-x C-u uppercase-region Make the region all uppercase.

8.Incremental Search Commands

C-s isearch-forward Start an incremental search forward.
C-r isearch-backward Starts an incremental search in the reverse direction.
Meta Stop a successful search.
C-g keyboard-quit Stop searching and return to the starting point.
Del Delete an incorrect character whilst searching.

9.Word Abbreviation Commands

abbrev-mode Enter abbreviation mode.
C-x – inverse-add-global-abbrev Type in a global abbreviation, then its meaning.
C-x C-h inverse-add-local-abbrev Type in a local abbreviation, then its meaning.
unexpand-abbrev Undo the last word abbreviation.
write-abbrev-file Write out the word abbreviation file.
edit-abbrevs Edit the current word abbreviations.
list-abbrevs View the current word abbreviations.
kill-all-abbrevs Kill any abreviations for this session.

10.Buffer Manipulation Commands

C-x b switch-to-buffer Move to the specified buffer.
C-x C-b list-buffers Display the list of currently active buffers.
C-x k kill-buffer Kill the current buffer
kill-some-buffers Ask about deleting each buffer currently active.
rename-buffer Rename the current buffer to something else.
C-x s save-some-buffers Ask whether to save each modified buffer

11.Window Commands

C-x 2 split-window-horizontally Divide the current window horizontally in two.
C-x 5 split-windws-vertically Divide the current window vertically in two.
C-x > scroll-right Scroll the window right.
C-x < scroll-left Scroll the window left.
C-x 0 delete-window Delete the current window.
C-x 1 delete-other-windows Delete all the windows except this one.
delete-windows-on Delete all windows open to a particular buffer.
C-x ^ enlarge-window Make the current window taller.
shrink-window Make the current window smaller.
C-x } enlarge-window-horizontally Make the window wider.
C-x { shrink-window-horizontally Make the window less wide.
M-C-v scroll-other-window Scroll the other window.
C-x 4 f find-file-other-window Find a file in the other window.
C-x 4 b switch-to-buffer-other-window Select a buffer in the other window.
compare-windows Compare two buffers and show the first difference.
C-x o other-window Select another window (letter “o”, not number 0)

12.Special Shell Characters

shell Start a shell.
C-c C-c interrupt-shell-subjob Terminate the current job in a shell.
C-c C-d send-shell-eof Send the EOF character (Ctrl-d)
C-c C-u kill-shell-input Erase the current line.
C-c C-w backward-kill-word Erase the previous word.
C-c C-z stop-shell-subjob Suspend the current shell job.

13.Indentation Commands

 C-x  set-fill-prefix  Prepend each line in paragraph with characters
from beginning of the line up to the current
cursor column.  cancel by doing this in column 1.
 M-C-\  indent-region  Indent a region to match the first line in region.
 M-m  back-to-indentation  Move the cursor to first character in line.
 M-C-o  split-line  Split line at cursor into two lines…  weird.
 fill-individual-paragraphs  Reformat indented paragraphs, keep indentation.

 

14.Centering Commands

M-s center-line Center the current line.
center-paragraph Center the paragraph that the cursor is on.
center-region Center the currently defined region.

 

15.Macro Commands

C-x ( start-kbd-macro Start a new macro definition.
C-x ) end-kbd-macro End the current macro definition.
C-x e call-last-kbd-macro Execute the last defined macro.
M-(number) C-x e call-last-kbd-maco Do that last macro (number times).
C-u C-x ( stat-kbd-macro Execute last macro and add to it.
name-last-kbd-macro Name the last macro before saving it.
insert-last-keyboard-macro Insert the macro you made into a file.
load-file Load a file with macros in it.
C-x q kbd-macro-query Insert a query into a keyboard macro.
M-C-c exit-recursive-edit Get the hell out of a recursive edit.

 

16.Detail Information Help Commands

C-h r info Open up the built-in manual
C-h a command-apropos What commands work like this…?
apropos What functions and variables work like this…?
C-h c describe-key-briefly What command does this key sequence do?
C-h b describe-bindings What are the key bindings for this buffer?
C-h k describe-key What command does this sequence do, and tell me about it.
C-h l view-lossage What are the last 100 characters typed?
C-h w where-is What is the key binding for this?
C-h f describe-function What does this function do?
C-h v describe-variable What is this variable?
C-h m describe-mode Tell me about this mode.
C-h s describe-syntax What is the syntax table for this buffer?

 

You’re welcome.