Emacs is the extensible, customizable, self-documenting real time display text editor. This reference was made for Emacs 27.
To enter Emacs, just type its name:
$ emacs
| - | - | 
|---|---|
| C-z | Suspend Emacs | 
| C-xC-c | Exit Emacs permanently | 
| - | - | 
|---|---|
| C-<key> | Means hold the control, and press <key> | 
| M-<key> | Means press the Esc once, and press <key> | 
NOTICE: This cheatsheet follows the above rules.
| Backward | Forward | Entity to move over | 
|---|---|---|
| C-b | C-f | Haracter | 
| M-b | M-f | Word | 
| C-p | C-n | Line | 
| C-a | C-e | Line beginning (or end) | 
| M-a | M-e | Sentence | 
| M-{ | M-} | Paragraph | 
| C-x[ | C-x] | Page | 
| C-M-b | C-M-f | Sexp | 
| C-M-a | C-M-e | Function | 
| M-< | M-> | Buffer beginning (or end) | 
| - | - | 
|---|---|
| M-u | Uppercase word | 
| M-l | Lowercase word | 
| M-c | Capitalize word | 
| C-xC-u | Uppercase region | 
| C-xC-l | Lowercase region | 
| - | - | 
|---|---|
| C-xC-f | Read a file into Emacs | 
| C-xC-s | Save a file back to disk | 
| C-xs | Save all files | 
| C-xi | Insert contents of another file into this buffer | 
| C-xC-v | Replace this file with your file | 
| C-xC-w | Write buffer to a specified file | 
| C-xC-q | Toggle read-only status of buffer | 
| - | - | 
|---|---|
| C-g | Abort partially typed or executing command | 
| M-xrecover-session | Recover files lost by a system crash | 
| C-xuC-_C-/ | Undo an unwanted change | 
| M-xrevert-buffer | Restore a buffer to its original contents | 
| C-l | Redraw garbaged screen | 
| - | - | 
|---|---|
| C-t | Transpose characters | 
| M-t | Transpose words | 
| C-xC-t | Transpose lines | 
| C-M-t | Transpose sexps | 
| - | - | 
|---|---|
| C-v | Scroll to next screen | 
| M-v | Scroll to previous screen | 
| C-x< | Scroll left | 
| C-x> | Scroll right | 
| C-l | Scroll current line to center, top, bottom | 
| - | - | 
|---|---|
| M-gg | Goto line | 
| M-gc | Goto char | 
| M-m | Back to indentation | 
| - | - | 
|---|---|
| C-@C-SPC | Uet mark here | 
| C-xC-x | Exchange point and mark | 
| M-@ | Set mark arg words away | 
| M-h | Mark paragraph | 
| C-xC-p | Mark page | 
| C-M-@ | Mark sexp | 
| C-M-h | Mark function | 
| C-xh | Mark entire buffer | 
| Backward | Forward | Entity to kill | 
|---|---|---|
| DEL | C-d | Character (delete) | 
| M-DEL | M-d | Word | 
| M-0C-k | C-k | Line (to end of) | 
| C-xDEL | M-k | Sentence | 
| M--C-M-k | C-M-k | Sexp | 
| - | - | 
|---|---|
| C-W | Kill region C-w | 
| M-w | Copy region to kill ring | 
| M-zchar | Kill through next occurrence of char | 
| C-y | Yank back last thing killed | 
| M-y | Replace last yank with previous kill | 
| - | - | 
|---|---|
| C-x1 | Remove help window | 
| C-M-v | Scroll help window | 
| C-ha | Apropos: show commands matching a string | 
| C-hk | Describe the function a key runs | 
| C-hf | Describe a function | 
| C-hm | Get mode-specific information | 
The help system is simple. Type C-h (or F1) and follow the directions. If you are a first-time user, type C-h t for a tutorial.
When two commands are shown, the second is a similar command for a frame instead of a window.
| - | - | - | 
|---|---|---|
| C-x51 | C-x1 | Delete all other windows | 
| C-x52 | C-x2 | Split window, above and below | 
| C-x50 | C-x0 | Delete this window | 
| C-x3 | Split window, side by side | |
| C-M-v | Scroll other window | |
| C-x5o | C-xo | Switch cursor to another window | 
| C-x5b | C-x4b | Select buffer in other window | 
| C-x5C-o | C-x4C-o | Display buffer in other window | 
| C-x5f | C-x4f | Find file in other window | 
| C-x5r | C-x4r | Find file read-only in other window | 
| C-x5d | C-x4d | Run Dired in other window | 
| C-x5. | C-x4. | Find tag in other window | 
| C-x^ | Grow window taller | |
| C-x{ | Shrink window narrower | |
| C-x} | Grow window wider | |
| - | - | 
|---|---|
| TAB | Indent current line (mode-dependent) | 
| C-M-\ | Indent region (mode-dependent) | 
| C-M-q | Indent sexp (mode-dependent) | 
| C-xTAB | Indent region rigidly arg columns | 
| M-; | Indent for comment | 
| C-o | Insert newline after point | 
| C-M-o | Move rest of line vertically down | 
| C-xC-o | Delete blank lines around point | 
| M-^ | Join line with previous (with arg, next) | 
| M-\ | Delete all white space around point | 
| M-SPC | Put exactly one space at point | 
| M-q | Fill paragraph | 
| C-xf | Set fill column to arg | 
| C-x. | Set prefix each line starts with | 
| M-o | Set face | 
| - | - | 
|---|---|
| C-hi | Enter the Info documentation reader | 
| C-hS | Find specified function or variable in Info | 
| - | - | 
|---|---|
| SPC | Scroll forward | 
| DEL | Scroll reverse | 
| b | Beginning of node | 
| - | - | 
|---|---|
| n | Next node | 
| p | Previous node | 
| u | Move up | 
| m | Select menu item by name | 
| n | Select nth menu item by number (1–9) | 
| f | Follow cross reference (return with l) | 
| l | Return to last node you saw | 
| d | Return to directory node | 
| t | Go to top node of Info file | 
| g | Go to any node by name | 
| - | - | 
|---|---|
| h | Run Info tutorial | 
| i | Look up a subject in the indices | 
| s | Search nodes for regexp | 
| q | Quit Info | 
The following keys are defined in the minibuffer.
| - | - | 
|---|---|
| TAB | Complete as much as possible | 
| SPC | Complete up to one word | 
| RET | Complete and execute | 
| ? | Show possible completions | 
| M-p | Fetch previous minibuffer input | 
| M-n | Fetch later minibuffer input or default | 
| M-r | Regexp search backward through history | 
| M-s | Regexp search forward through history | 
| C-g | Abort command | 
Type C-x ESC ESC to edit and repeat the last command that used the minibuffer. Type F10 to activate menu bar items on text terminals.
| - | - | 
|---|---|
| M-. | Find a tag (a definition) | 
| C-uM-. | Find next occurrence of tag | 
| M-xvisit-tags-table | Specify a new tags file | 
| M-xtags-search | Regexp search on all files in tags table | 
| M-xtags-query-replace | Run query-replace on all the files | 
| M-, | Continue last tags search or query-replace | 
| - | - | 
|---|---|
| C-xrr | Copy rectangle to register | 
| C-xrk | Kill rectangle | 
| C-xry | Yank rectangle | 
| C-xro | Open rectangle, shifting text right | 
| C-xrc | Blank out rectangle | 
| C-xrt | Prefix each line with a string | 
| - | - | 
|---|---|
| C-x( | Start defining a keyboard macro | 
| C-x) | End keyboard macro definition | 
| C-xe | Execute last-defined keyboard macro | 
| C-uC-x( | Append to last keyboard macro | 
| M-xname-last-kbd-macro | Name last keyboard macro | 
| M-xinsert-kbd-macro | Insert Lisp definition in buffer | 
| - | - | 
|---|---|
| C-xb | Select another buffer | 
| C-xC-b | List all buffers | 
| C-xk | Kill a buffer | 
| - | - | 
|---|---|
| .(dot) | Any single character except a newline | 
| * | Zero or more repeats | 
| + | One or more repeats | 
| ? | Zero or one repeat | 
| \ | Quote special characters | 
| \c | Quote regular expression special character c | 
| \| | Alternative (“or”) | 
| \(...\) | Grouping | 
| \(:?...\) | Shy grouping | 
| \(:NUM...\) | Explicit numbered grouping | 
| \n | Same text as nth group | 
| \b | At word break | 
| \B | Not at word break | 
| Start | End | Entity | 
|---|---|---|
| ^ | $ | Line | 
| \< | \> | Word | 
| \_< | \_> | Symbol | 
| \‘ | \’ | Buffer | 
| These | Others | class | 
|---|---|---|
| [...] | [^...] | Explicit set | 
| \w | \W | Word-syntax character | 
| \sc | \Sc | Character with syntax c | 
| \cc | \Cc | Character with category c | 
| - | - | 
|---|---|
| C-s | Search forward | 
| C-r | Search backward | 
| C-M-s | Regular expression search | 
| C-M-r | Reverse regular expression search | 
| M-p | Select previous search string | 
| M-n | Select next later search string | 
| RET | Exit incremental search | 
| DEL | Undo effect of last character | 
| C-g | Abort current search | 
Use C-s or C-r again to repeat the search in either direction. If Emacs is still searching, C-g cancels only the part not matched.
| - | - | 
|---|---|
| M-% | Interactively replace a text string | 
| M-xregexp | Using regular expressions | 
| SPC/y | Replace this one, go on to next | 
| , | Replace this one, don’t move | 
| DEL/n | Skip to next without replacing | 
| ! | Replace all remaining matches | 
| ^ | Back up to the previous match | 
| RET | Exit query-replace | 
| C-r | Enter recursive edit (C-M-c to exit) | 
| - | - | 
|---|---|
| M-! | Execute a shell command | 
| M-& | Execute a shell command asynchronously | 
| M- | Run a shell command on the region | 
| C-uM- | Filter region through a shell command | 
| M-xshell | Start a shell in window shell | 
| - | - | 
|---|---|
| C-xRETl | specify principal language | 
| M-xlist-input-methods | show all input methods | 
| C-\ | enable or disable input method | 
| C-xRETc | set coding system for next command | 
| M-xlist-coding-systems | show all coding systems | 
| M-xprefer-coding-system | choose preferred coding system | 
| - | - | 
|---|---|
| C-xrs | Save region in register | 
| C-xri | Insert register contents into buffer | 
| C-xrSPC | Save value of point in register | 
| C-xrj | Jump to point saved in register | 
| - | - | 
|---|---|
| C-unum | Numeric argument | 
| M-- | Negative argument | 
| C-qchar | Quoted insert | 
| - | - | 
|---|---|
| C-xC-e | Eval sexp before point | 
| C-M-x | Eval current defun | 
| M-xeval-region | Eval region | 
| M-: | Read and eval minibuffer | 
| M-xload-library | Load a Lisp library from load-path | 
| - | - | 
|---|---|
| M-xcustomize | customize variables and faces | 
Making global key bindings in Emacs Lisp:
(global-set-key (kbd "C-c g") ’search-forward)
(global-set-key (kbd "M-#") ’query-replace-regexp)
| - | - | 
|---|---|
| C-xag | Add global abbrev | 
| C-xal | Add mode-local abbrev | 
| C-xaig | Add global expansion for this abbrev | 
| C-xail | Add mode-local expansion for this abbrev | 
| C-xae | Explicitly expand abbrev | 
| M-/ | Expand previous word dynamically | 
| - | - | 
|---|---|
| M-$ | Check spelling of current word | 
| M-xispell-region | Check spelling of all words in region | 
| M-xispell-buffer | Check spelling of entire buffer | 
| M-xflyspell-mode | Toggle on-the-fly spell checking | 
(defun command-name (args)
"documentation" (interactive "template")
body)
(defun this-line-to-top-of-window (line)
    "Reposition current line to top of window.
With prefix argument LINE, put point on LINE."
    (interactive "P")
    (recenter (if (null line)
                  0
              (prefix-numeric-value line))))
The interactive spec says how to read arguments interactively. Type C-h f interactive RET for more details.