You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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 {.cols-3}
Starting Emacs
To enter Emacs, just type its name:
$ emacs
-
-
C-z
Suspend Emacs
C-xC-c
Exit Emacs permanently
{.shortcuts}
Global Description {.secondary}
-
-
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 {.row-span-2}
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 {.row-span-2}
-
-
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 {.row-span-2}
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 {.col-span-2}
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 |
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 |
{.shortcuts}
Type C-xESCESC to edit and repeat the last command that used the minibuffer. Type F10 to activate menu bar items on text terminals.
Tags
-
-
M-.
Find a tag (a definition)
C-uM-.
Find next occurrence of tag
M-x visit-tags-table
Specify a new tags file
M-x tags-search
Regexp search on all files in tags table
M-x tags-query-replace
Run query-replace on all the files
M-,
Continue last tags search or query-replace
{.shortcuts}
Rectangles
-
-
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
{.shortcuts}
Keyboard Macros
-
-
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-x name-last-kbd-macro
Name last keyboard macro
M-x insert-kbd-macro
Insert Lisp definition in buffer
{.shortcuts}
Buffers
-
-
C-xb
Select another buffer
C-xC-b
List all buffers
C-xk
Kill a buffer
{.shortcuts}
Emacs Search{.cols-3}
Regex (common) {.row-span-2}
-
-
.(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
Regex (entry)
Start
End
Entity
^
$
Line
\<
\>
Word
\_<
\_>
Symbol
\‘
\’
Buffer
{.show-header}
Regex (conflict)
These
Others
class
[...]
[^...]
Explicit set
\w
\W
Word-syntax character
\sc
\Sc
Character with syntax c
\cc
\Cc
Character with category c
{.show-header}
Incremental Search
-
-
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
{.shortcuts}
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.
(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.