logo
🛠️ 开发工具

Emacs

Emacs Cheat Sheet - 快速参考指南,收录常用语法、命令与实践。

📂 分类 · 开发工具🧭 Markdown 速查🏷️ 2 个标签
#emacs#editor
向下滚动查看内容
返回全部 Cheat Sheets

Getting started

Starting Emacs

To enter Emacs, just type its name:

SHELL
滚动查看更多
$ emacs

--
C-zSuspend Emacs
C-x C-cExit 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
BackwardForwardEntity to move over
C-bC-fHaracter
M-bM-fWord
C-pC-nLine
C-aC-eLine beginning<br/>(or end)
M-aM-eSentence
M-{M-}Paragraph
C-x [C-x ]Page
C-M-bC-M-fSexp
C-M-aC-M-eFunction
M-<M->Buffer beginning<br>(or end)

{.shortcuts .show-header}

Case Change
--
M-uUppercase word
M-lLowercase word
M-cCapitalize word
C-x C-uUppercase region
C-x C-lLowercase region

{.shortcuts}

Files
--
C-x C-fRead a file into Emacs
C-x C-sSave a file back to disk
C-x sSave all files
C-x iInsert contents of another file into this buffer
C-x C-vReplace this file with your file
C-x C-wWrite buffer to a specified file
C-x C-qToggle read-only status of buffer

{.shortcuts}

Error Recovery
--
C-gAbort partially typed or executing command
M-x recover-sessionRecover files lost by a system crash
C-x u<br>C-_<br>C-/Undo an unwanted change
M-x revert-bufferRestore a buffer to its original contents
C-lRedraw garbaged screen

{.shortcuts}

Transposing
--
C-tTranspose characters
M-tTranspose words
C-x C-tTranspose lines
C-M-tTranspose sexps

{.shortcuts .table-fixed}

Scroll

--
C-vScroll to next screen
M-vScroll to previous screen
C-x <Scroll left
C-x >Scroll right
C-lScroll current line to <br>center, top, bottom

{.shortcuts .table-fixed}

Goto

--
M-g gGoto line
M-g cGoto char
M-mBack to indentation

{.shortcuts .table-fixed}

Marking
--
C-@<br/>C-SPCUet mark here
C-x C-xExchange point and mark
M-@Set mark arg words away
M-hMark paragraph
C-x C-pMark page
C-M-@Mark sexp
C-M-hMark function
C-x hMark entire buffer

{.shortcuts}

Killing and Deleting
BackwardForwardEntity to kill
DELC-dCharacter <br>(delete)
M-DELM-dWord
M-0 C-kC-kLine <br/> (to end of)
C-x DELM-kSentence
M-- C-M-kC-M-kSexp

{.shortcuts .show-header}

Killing

--
C-WKill region C-w
M-wCopy region to kill ring
M-z charKill through next occurrence of char
C-yYank back last thing killed
M-yReplace last yank with previous kill

{.shortcuts}

Getting Help
--
C-x 1Remove help window
C-M-vScroll help window
C-h aApropos: show commands matching a string
C-h kDescribe the function a key runs
C-h fDescribe a function
C-h mGet 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 1C-x 1Delete all other windows
C-x 5 2C-x 2Split window, above and below
C-x 5 0C-x 0Delete this window
C-x 3Split window, side by side
C-M-vScroll other window
C-x 5 oC-x oSwitch cursor to another window
C-x 5 bC-x 4 bSelect buffer in other window
C-x 5 C-oC-x 4 C-oDisplay buffer in other window
C-x 5 fC-x 4 fFind file in other window
C-x 5 rC-x 4 rFind file read-only in other window
C-x 5 dC-x 4 dRun Dired in other window
C-x 5 .C-x 4 .Find tag in other window
C-x ^Grow window taller
C-x {Shrink window narrower
C-x }Grow window wider

{.shortcuts}

Formatting
--
TABIndent current line (mode-dependent)
C-M-\Indent region (mode-dependent)
C-M-qIndent sexp (mode-dependent)
C-x TABIndent region rigidly arg columns
M-;Indent for comment
C-oInsert newline after point
C-M-oMove rest of line vertically down
C-x C-oDelete blank lines around point
M-^Join line with previous (with arg, next)
M-\Delete all white space around point
M-SPCPut exactly one space at point
M-qFill paragraph
C-x fSet fill column to arg
C-x .Set prefix each line starts with
M-oSet face

{.shortcuts}

Info
--
C-h iEnter the Info documentation reader
C-h SFind specified function or variable in Info

{.shortcuts .table-fixed}

Moving within a node

--
SPCScroll forward
DELScroll reverse
bBeginning of node

{.shortcuts .table-fixed}

Moving between nodes

--
nNext node
pPrevious node
uMove up
mSelect menu item by name
nSelect nth menu item by number (1–9)
fFollow cross reference (return with l)
lReturn to last node you saw
dReturn to directory node
tGo to top node of Info file
gGo to any node by name

{.shortcuts .table-fixed}

Other

--
hRun Info tutorial
iLook up a subject in the indices
sSearch nodes for regexp
qQuit Info

{.shortcuts .table-fixed}

Minibuffer

The following keys are defined in the minibuffer.

--
TABComplete as much as possible
SPCComplete up to one word
RETComplete and execute
?Show possible completions
M-pFetch previous minibuffer input
M-nFetch later minibuffer input or default
M-rRegexp search backward through history
M-sRegexp search forward through history
C-gAbort command

{.shortcuts}

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.

Tags
--
M-.Find a tag (a definition)
C-u M-.Find next occurrence of tag
M-x visit-tags-tableSpecify a new tags file
M-x tags-searchRegexp search on all files in tags table
M-x tags-query-replaceRun query-replace on all the files
M-,Continue last tags search or query-replace

{.shortcuts}

Rectangles
--
C-x r rCopy rectangle to register
C-x r kKill rectangle
C-x r yYank rectangle
C-x r oOpen rectangle, shifting text right
C-x r cBlank out rectangle
C-x r tPrefix each line with a string

{.shortcuts}

Keyboard Macros
--
C-x (Start defining a keyboard macro
C-x )End keyboard macro definition
C-x eExecute last-defined keyboard macro
C-u C-x (Append to last keyboard macro
M-x name-last-kbd-macroName last keyboard macro
M-x insert-kbd-macroInsert Lisp definition in buffer

{.shortcuts}

Buffers
--
C-x bSelect another buffer
C-x C-bList all buffers
C-x kKill a buffer

{.shortcuts}

Emacs Search

Regex (common)
--
. (dot)Any single character except a newline
*Zero or more repeats
+One or more repeats
?Zero or one repeat
\Quote special characters
\cQuote regular expression special character c
|Alternative (“or”)
\(...\)Grouping
\(:?...\)Shy grouping
\(:NUM...\)Explicit numbered grouping
\nSame text as nth group
\bAt word break
\BNot at word break
Regex (entry)
StartEndEntity
^$Line
\<\>Word
\_<\_>Symbol
\‘\’Buffer

{.show-header}

Regex (conflict)
TheseOthersclass
[...][^...]Explicit set
\w\WWord-syntax character
\sc\ScCharacter with syntax c
\cc\CcCharacter with category c

{.show-header}

Incremental Search
--
C-sSearch forward
C-rSearch backward
C-M-sRegular expression search
C-M-rReverse regular expression search
M-pSelect previous search string
M-nSelect next later search string
RETExit incremental search
DELUndo effect of last character
C-gAbort 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.

Query Replace
--
M-%Interactively replace a text string
M-x regexpUsing regular expressions
SPC / yReplace this one, go on to next
,Replace this one, don’t move
DEL / nSkip to next without replacing
!Replace all remaining matches
^Back up to the previous match
RETExit query-replace
C-rEnter recursive edit (C-M-c to exit)

{.shortcuts}

Misc

Shells
--
M-!Execute a shell command
M-&Execute a shell command asynchronously
M-Run a shell command on the region
C-u M-Filter region through a shell command
M-x shellStart a shell in window shell

{.shortcuts}

International Character Sets
--
C-x RET lspecify principal language
M-x list-input-methodsshow all input methods
C-\enable or disable input method
C-x RET cset coding system for next command
M-x list-coding-systemsshow all coding systems
M-x prefer-coding-systemchoose preferred coding system

{.shortcuts}

Registers
--
C-x r sSave region in register
C-x r iInsert register contents into buffer
C-x r SPCSave value of point in register
C-x r jJump to point saved in register

{.shortcuts}

Miscellaneous
--
C-u numNumeric argument
M--Negative argument
C-q charQuoted insert

{.shortcuts}

Commands Dealing with Emacs Lisp
--
C-x C-eEval sexp before point
C-M-xEval current defun
M-x eval-regionEval region
M-:Read and eval minibuffer
M-x load-libraryLoad a Lisp library from load-path

{.shortcuts}

Simple Customization
--
M-x customizecustomize variables and faces

Making global key bindings in Emacs Lisp:

{.WRAP}
滚动查看更多
(global-set-key (kbd "C-c g") ’search-forward)
(global-set-key (kbd "M-#") ’query-replace-regexp)
Abbrevs
--
C-x a gAdd global abbrev
C-x a lAdd mode-local abbrev
C-x a i gAdd global expansion for this abbrev
C-x a i lAdd mode-local expansion for this abbrev
C-x a eExplicitly expand abbrev
M-/Expand previous word dynamically

{.shortcuts}

Spelling Check
--
M-$Check spelling of current word
M-x ispell-regionCheck spelling of all words in region
M-x ispell-bufferCheck spelling of entire buffer
M-x flyspell-modeToggle on-the-fly spell checking

{.shortcuts}

Writing Commands

Syntax

LISP
滚动查看更多
(defun command-name (args)
"documentation" (interactive "template")
body)

Example

LISP
滚动查看更多
(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.

相关 Cheat Sheets

1v1免费职业咨询
logo

Follow Us

linkedinfacebooktwitterinstagramweiboyoutubebilibilitiktokxigua

We Accept

/image/layout/pay-paypal.png/image/layout/pay-visa.png/image/layout/pay-master-card.png/image/layout/pay-airwallex.png/image/layout/pay-alipay.png

地址

Level 10b, 144 Edward Street, Brisbane CBD(Headquarter)
Level 2, 171 La Trobe St, Melbourne VIC 3000
四川省成都市武侯区桂溪街道天府大道中段500号D5东方希望天祥广场B座45A13号
Business Hub, 155 Waymouth St, Adelaide SA 5000

Disclaimer

footer-disclaimerfooter-disclaimer

JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.

匠人学院网站上的所有内容,包括课程材料、徽标和匠人学院网站上提供的信息,均受澳大利亚政府知识产权法的保护。严禁未经授权使用、销售、分发、复制或修改。违规行为可能会导致法律诉讼。通过访问我们的网站,您同意尊重我们的知识产权。 JR Academy Pty Ltd 保留所有权利,包括专利、商标和版权。任何侵权行为都将受到法律追究。查看用户协议

© 2017-2025 JR Academy Pty Ltd. All rights reserved.

ABN 26621887572