Skip to content

Instantly share code, notes, and snippets.

@Nuclearfossil
Last active May 14, 2019 13:41
Show Gist options
  • Save Nuclearfossil/26009e0d1c990344a864 to your computer and use it in GitHub Desktop.
Save Nuclearfossil/26009e0d1c990344a864 to your computer and use it in GitHub Desktop.
Emacs Cheat Sheet

A simple cheatsheet for Emacs

Legend

  C- = Ctrl + additional key
  M- = Alt + additional key(s)

Pane commands

   Key        | Description
   -----------|---------------------------------------------------------------------
   Ctrl-2     | Split Horizontally
   Ctrl-3     | Split Vertically
   Ctrl-x, o  | Switch to other wndow
   Ctrl-x, 40 | Delete the selected window and buffer
   Ctrl-x, ^  | Make selected window taller
   Ctrl-x, }  | Make selected window wider
   Ctrl-x, {  | Make selected window narrowr
   Ctrl-Alt-v | Scroll other window

Cursor motion

   Amount      | Move > | Move < |  Del >  | Del <
   ------------|--------|--------|---------|-------
   Characters  |  C-f   |  C-b   | C-d     | DEL
   Words       |  M-f   |  M-b   | M-d     | M-DEL
   Lines       |  C-n   |  C-p   | C-k(EOL)| C-SPC C-a C-w
     - More    |  C-e   |  C-a   |         |
   Sentences   |  M-e   |  M-a   | M-k     | C-x DEL
   Expressions |  C-M-f |  C-M-b | C-M-k   | C-M-DEL
   Paragraphs  |  M-}   |  M-{   |         |
   Buffer      |  M->   |  M-<   |         | 

Scrolling and Windows

   Binding | Description
   --------|------------------------------------------------------------------------
   C-v     | Scroll down (toward end of buffer)
   M-v     | Scroll up (toward beginning of buffer)
   C-M-v   | Scroll other window down
   C-x 1   | One window on current buffer
   C-x 2   | Split window vertically
   C-x 3   | Split window horizontally
   C-x ^   | Grow window vertically; prefix is number of lines

Commands

   Binding | Description
   --------|------------------------------------------------------------------------
   C-u #   | Prefix numeric arg # (digits with optional "-" sign) to next cmd
   C-g     | Stop a command in progress, or quit out of a partially entered command
  • ESC ESC ESC - Get me out of where I am now

Getting help

   Binding | Description
   --------|------------------------------------------------------------------------
   C-h k   | Show command documentation; prompts for keystrokes
   C-h a   | "Command apropos"; prompts for regexp and shows all matching commands
   C-h c   | Show command name on message line; prompts for keystrokes
   C-h f   | Describe function; prompts for command or function name, shows 
           | documentation in other window
   C-h i   | Info browser; gives access to online documentation for emacs and more

Miscellaneous

   Binding | Description
   --------|------------------------------------------------------------------------
   C-_     | 
   C-x u   | Undo/redo (a series of these keeps undoing; after doing something else,
           | C-_ or C-x u will undo the undo's)
   C-q	   | Quoted insert; inserts the next character typed, even if it is a control
           | or meta character
   M-x     | shell-strip-ctrl-m RET	Flush ^M at end of line
   C-z	   | Suspend/iconify emacs (type "%emacs" in invoking shell to get it back)
   C-x C-c | Exit emacs (asks about unsaved buffers and running programs)

Cutting and Pasting

   Binding | Description
   --------|------------------------------------------------------------------------
   C-SPC   | Mark one end of region
   C-w	   | Cut (after you Mark and move to other end)
   M-w	   | Copy (after you Mark and move to other end)
   C-y	   | Yank (paste) most recently killed (cut or copied); will also use text
           | currently selected in another application.
   M-y	   | Next most recently killed (do C-y first, repeat M-y to cycle thru all)

To make cut/copy/paste behave as it does in other apps, do M-x cua-mode, or put

(cua-mode)

in your .emacs to enable in every session.

Files and Buffers

   Binding | Description
   --------|------------------------------------------------------------------------
   C-x C-f | Find file (or create if not there); prompts for file name
   C-x C-s | Save file
   C-x C-w | Write file; prompts for new name
   C-x s   | Save modified buffers; asks about each
   C-x b   | Select buffer; prompts for buffer name
   C-x C-b | List buffers; shows in other window
   C-x k   | Kill buffer; prompts for buffer name

Searching/Replacing

   Binding | Description
   --------|------------------------------------------------------------------------
   C-s     | Incremental search forward; searches as you type
   C-r     | Incremental search backward
   C-M-s   | Regexp search forward (there are differences in Emacs regexp syntax wrt
           | Perl, etc.)
   C-M-r   | Regexp search backward
   M-x     | replace-string RET	String replace from here to end of buffer; prompts
           | for string and replacement
   M-x     | query-replace RET	String replace from here to end of buffer, querying
           | for each occurrence
   M-x     | grep RET	Prompts for a grep command, shows hits in a buffer
   C-x `   | Visit next grep hit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment