Buffers and Windows

  1. C-x C-f find file (open in current buffer)
  2. C-x C-s save contents of current buffer
  3. C-x C-c kill (close) Emacs
  4. C-x s save all buffers
  5. C-x C-w save current buffer with specified name
  6. C-x k kill (close) current buffer
  7. C-x C-b list existing buffers
  8. C-x b select buffer by name
  9. C-x 2 split current window in two vertically
  10. C-x 3 split current window in two horizontally
  11. C-x 0 delete the current window
  12. C-x 1 delete all windows but the current
  13. C-x o switch to other window
  14. C-M-v scroll other window down
  15. M-: (set-frame-width (selected-frame) n) set frame width to n characters
  16. M-: (set-frame-height (selected-frame) n) set frame height to n characters
  1. C-f move cursor forward
  2. C-b move cursor backward
  3. C-n move cursor to next line
  4. C-p move cursor to previous line
  5. M-f move cursor forward one token
  6. M-b move cursor backward one token
  7. C-l center screen on cursor
  8. C-a move cursor to beginning of line
  9. C-e move cursor to end of line
  10. C-v move down one screenful
  11. M-v move cursor up one screenful
  12. M-< move cursor to beginning of buffer
  13. M-> move cursor to end of buffer
  14. M-x goto-line go to line
  15. M-a move cursor to beginning of statement
  16. M-e move cursor to end of statement
  17. M C-a move cursor to beginning of function
  18. M C-e move cursor to end of function


  1. C-<SPC>  set mark (mark is the beggining of region; cursor is end of region)
  2. C-x C-p set region to entire buffer
  3. C-k kill (cut) from cursor to end of line
  4. C-w kill (cut) region
  5. M-w save (copy) region
  6. C-y yank (paste) what was most recently killed
  7. M-y yank-pop (cycle though) earlier kills, after yanking
  8. <Backspace> delete character before cursor
  9. C-d delete character at cursor
  10. M-<Backspace> delete from cursor to beginning of token
  11. M-d delete from cursor to end of token
  12. M-\ delete horizontal space
  13. M-; comment/un-comment region
  14. <TAB> indent line
  15. C-c > indent region
  16. C-c < exdent region
  17. C-/ undo
  18. M-/ auto complete
  19. M-q fill paragraph (useful for wrapping lines in comments)


  1. C-s forward incremental search
  2. C-r reverse incremental search
  3. <RET> (when in search mode) stop searching
  4. C-g (when in search mode) cancel search and return to where search started
  5. M-y (when in search mode) yank most recent kill into seach string
  6. M-% search_string replace_string query replace occurances of search_string with replace_string
  7. y (when in query replace mode) replace highlighted search_string
  8. (when in query replace mode) do not replace highlighted search_string
  9. q (when in query replace mode) exit query replace mode
  10. M-x grep search_string file_name1 file_name2 ... search for search_string in the specified files (note the files do not have to be currently open)
  11. M-x grep search_string * search for search_string in all files in the current directory
  12. C-x ` select next search_string in grep buffer

Compiling and Running

  1. M-x compile run compile command in other window
  2. C-x ` select next error in compile buffer
  3. M-x shell open shell in this window
  4. M-p previous command (while cursor is at the command prompt in the shell)
  5. C-c C-c kill currently running program (while in the shell)


The following can be put in the ~/.emacs.d/init.el file to configure Emacs

  1. On Windows, if the Emacs shell does not recognize the python command:

    (setenv "PATH" (concat (getenv "PATH") ";C:\\path\\to\\python"))
  2. On OS X, if the Emacs shell does not recognize the python command:

    (setenv "PATH" (concat (getenv "PATH") ":/path/to/python"))
  3. To set the initial font size of an Emacs window (FONT_SIZE is the initial font size times ten):

    (set-face-attribute 'default nil :height FONT_SIZE)
  4. To set the initial dimensions of an Emacs window (CHARS_WIDE and CHARS_HIGH are the number of characters that will fit in the window horizontally and vertically):

    (setq default-frame-alist '((width . CHARS_WIDE) (height . CHARS_HIGH)))