[Emacs](https://www.gnu.org/software/emacs) is the extensible, customizable, self-documenting real time display text editor.
This reference was made for Emacs 27.
Getting started
Starting Emacs
To enter Emacs, just type its name:
$ emacs
-
-
C-z
Suspend Emacs
C-xC-c
Exit Emacs permanently
{.shortcuts}
Global Description
-
-
C-<key>
Means hold the control, and press <key>
M-<key>
Means press the Esc once, and press <key>
{.shortcuts}
NOTICE: This cheatsheet follows the above rules.
Motion
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)
{.shortcuts .show-header}
Case Change
-
-
M-u
Uppercase word
M-l
Lowercase word
M-c
Capitalize word
C-xC-u
Uppercase region
C-xC-l
Lowercase region
{.shortcuts}
Files
-
-
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
{.shortcuts}
Error Recovery
-
-
C-g
Abort partially typed or executing command
M-x recover-session
Recover files lost by a system crash
C-xu C-_ C-/
Undo an unwanted change
M-x revert-buffer
Restore a buffer to its original contents
C-l
Redraw garbaged screen
{.shortcuts}
Transposing
-
-
C-t
Transpose characters
M-t
Transpose words
C-xC-t
Transpose lines
C-M-t
Transpose sexps
{.shortcuts}
Scroll
-
-
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
{.shortcuts}
Goto
-
-
M-gg
Goto line
M-gc
Goto char
M-m
Back to indentation
{.shortcuts}
Marking
-
-
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
{.shortcuts}
Killing and Deleting
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
{.shortcuts .show-header}
Killing
-
-
C-W
Kill region C-w
M-w
Copy region to kill ring
M-z char
Kill through next occurrence of char
C-y
Yank back last thing killed
M-y
Replace last yank with previous kill
{.shortcuts}
Getting Help
-
-
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
{.shortcuts}
The help system is simple. Type C-h (or F1) and follow the directions. If you are a first-time user, type C-ht for a tutorial.
Multiple Windows
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 |
(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-hf interactive RET for more details.