Buffers and Windows
- C-x C-f find file (open in current buffer)
- C-x C-s save contents of current buffer
- C-x C-c kill (close) Emacs
- C-x s save all buffers
- C-x C-w save current buffer with specified name
- C-x k kill (close) current buffer
- C-x C-b list existing buffers
- C-x b select buffer by name
- C-x 2 split current window in two vertically
- C-x 3 split current window in two horizontally
- C-x 0 delete the current window
- C-x 1 delete all windows but the current
- C-x o switch to other window
- C-M-v scroll other window down
- M-: (set-frame-width (selected-frame) n) set frame width to n characters
- M-: (set-frame-height (selected-frame) n) set frame height to n characters
Navigating
- C-f move cursor forward
- C-b move cursor backward
- C-n move cursor to next line
- C-p move cursor to previous line
- M-f move cursor forward one token
- M-b move cursor backward one token
- C-l center screen on cursor
- C-a move cursor to beginning of line
- C-e move cursor to end of line
- C-v move down one screenful
- M-v move cursor up one screenful
- M-< move cursor to beginning of buffer
- M-> move cursor to end of buffer
- M-x goto-line go to line
- M-a move cursor to beginning of statement
- M-e move cursor to end of statement
- M C-a move cursor to beginning of function
- M C-e move cursor to end of function
Editing
- C-<SPC> set mark (mark is the beggining of region; cursor is end of region)
- C-x C-p set region to entire buffer
- C-k kill (cut) from cursor to end of line
- C-w kill (cut) region
- M-w save (copy) region
- C-y yank (paste) what was most recently killed
- M-y yank-pop (cycle though) earlier kills, after yanking
- <Backspace> delete character before cursor
- C-d delete character at cursor
- M-<Backspace> delete from cursor to beginning of token
- M-d delete from cursor to end of token
- M-\ delete horizontal space
- M-; comment/un-comment region
- <TAB> indent line
- C-c > indent region
- C-c < exdent region
- C-/ undo
- M-/ auto complete
- M-q fill paragraph (useful for wrapping lines in comments)
Searching
- C-s forward incremental search
- C-r reverse incremental search
- <RET> (when in search mode) stop searching
- C-g (when in search mode) cancel search and return to where search started
- M-y (when in search mode) yank most recent kill into seach string
- M-% search_string
replace_string query replace occurances of search_string with replace_string - y (when in query replace mode) replace highlighted search_string
(when in query replace mode) do not replace highlighted search_string- q (when in query replace mode) exit query replace mode
- 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) - M-x grep
search_string * search for search_string in all files in the current directory - C-x ` select next search_string in grep buffer
Compiling and Running
- M-x compile run compile command in other window
- C-x ` select next error in compile buffer
- M-x shell open shell in this window
- M-p previous command (while cursor is at the command prompt in the shell)
- C-c C-c kill currently running program (while in the shell)
Configuring
The following can be put in the ~/.emacs.d/init.el
file to configure Emacs
On Windows, if the Emacs shell does not recognize the python command:
(setenv "PATH" (concat (getenv "PATH") ";C:\\path\\to\\python"))
On OS X, if the Emacs shell does not recognize the python command:
(setenv "PATH" (concat (getenv "PATH") ":/path/to/python"))
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)
To set the initial dimensions of an Emacs window (
CHARS_WIDE
andCHARS_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)))