[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 GNU Emacs 27, just type its name:
$ emacs
-
-
C-z
Suspend Emacs (or iconify it under X)
C-xC-c
Exit Emacs permanently
{.shortcuts}
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
To 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->
To buffer beginning (or end)
{.shortcuts .show-header}
Case Change
-
-
M-u
Uppercase word
M-l
Lowercase word
M-c
Capitalize word
C-x C-u
Uppercase region
C-x C-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-x u / 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-x C-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 .show-header}
Goto
-
-
M-g g
Goto line
M-g c
Goto char
M-m
Back to indentation
{.shortcuts .show-header}
Marking
-
-
C-@ / C-SPC
Uet mark here
C-x C-x
Exchange point and mark
M-@
Set mark arg words away
M-h
Mark paragraph
C-x C-p
Mark page
C-M-@
Mark sexp
C-M-h
Mark function
C-x h
Mark entire buffer
{.shortcuts}
Killing and Deleting
Backward
Forward
Entity to kill
DEL
C-d
Character (delete, not kill)
M-DEL
M-d
Word
M-0 C-k
C-k
Line (to end of)
C-x DEL
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-x 1
Remove help window
C-M-v
Scroll help window
C-h a
Apropos: show commands matching a string
C-h k
Describe the function a key runs
C-h f
Describe a function
C-h m
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-h t for a tutorial.
Multiple Windows
When two commands are shown, the second is a similar command for a frame instead of a window.
-------------
-------------
-------------------------------------
C-x 5 1
C-x 1
Delete all other windows
C-x 5 2
C-x 2
Split window, above and below
C-x 5 0
C-x 0
Delete this window
| C-x 3 || Split window, side by side |
| C-M-v || Scroll other window |
| C-x 5 o | C-x o | Switch cursor to another window |
| C-x 5 b | C-x 4 b | Select buffer in other window |
| C-x 5 C-o | C-x 4 C-o | Display buffer in other window |
| C-x 5 f | C-x 4 f | Find file in other window |
| C-x 5 r | C-x 4 r | Find file read-only in other window |
| C-x 5 d | C-x 4 d | Run Dired in other window |
| C-x 5 . | C-x 4 . | 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-h f interactive RET for more details.