reddit / emacs

Here's a list of Emacs keyboard shortcuts that I use on a regular basis, might be useful to some.

VernonGrant · 2022-09-02 14:48
I also made a repository for this, just in case someone want to bookmark it: [Emacs keyboard Shortcuts](https://github.com/VernonGrant/emacs-keyboard-shortcuts) ## General Shortcuts |Shortcut|Command Invoked|Description| |:-|:-|:-| |`C-x Esc Esc`|`repeat-complex-command`|Edit and re-evaluate last complex command.| |`C-h m`|`describe-mode`|Help information for the current buffers modes.| |`C-h f`|`describe-function`|Help information for a function.| |`C-h x`|`describe-command`|Help information for a command (a function available using `M-x`).| |`C-h l`|`view-lossage`|Show log for key presses and commands.| |`C-k`|`kill-line`|Kill rest of line, or line if empty.| |`C-/`|`undo`|Undo.| |`C-g C-/`|`undo-redo`|Redo.| |`C-y`|`yank`|Yank from kill ring.| |`M-y`|`yank-pop`|Yank down the kill ring.| |`C-y M-y`|`yank-pop`|Cycle through kills after a yank.| |`M-/`|`dabbrev-expand`|Dabbrev (word) expand.| |`M-C-/`|`dabbrev-completion`|Dabbrev (word) completion.| |`C-x s`|`save-some-buffers`|Save all buffers.| |`C-x C-s`|`save-buffer`|Save current buffer.| |`C-x C-w`|`write-file`|Write the current buffer, can provide new file name.| |`C-o`|`open-line`|Add blank line below.| |`C-x C-o`|`delete-blank-lines`|Delete all blank lines below.| |`C-x C-c`|`save-buffers-kill-terminal`|Quit Emacs.| |`M--`|`negative-argument`|Prefix to perform negative meta commands.| |`C--`|`negative-argument`|Prefix to perform negative commands.| |`C-a`|`move-beginning-of-line`|Move cursor to the beginning of the line.| |`C-e`|`move-end-of-line`|Move cursor to the end of the line.| |`M-a`|`backward-sentence`|Move cursor to the beginning of the sentence.| |`M-e`|`forward-sentence`|Move cursor to the end of the sentence.| |`M-m`|`back-to-indentation`|Move cursor to the first non-whitepsace character on the line.| |`M-k`|`kill-sentence`|Kill rest the rest of theing of the line.| |`M-l`|`downcase-word`|Lowercase word forward.| |`M-c`|`capitalize-word`|Capitalize word forward.| |`M-u`|`upcase-word`|Uppercase word forward.| |`C-<space> C-<space>`|`set-mark-command`|Add mark to mark ring.| |`C-u C-<space>`|`set-mark-command`|Jump to previous mark.| |`C-x f`|`set-fill-column`|Set fill column number.| |`M-q`|`fill-paragraph`|Wrap/reformat to fill column.| |`M-v`|`scroll-down-command`|Page up.| |`C-v`|`scroll-up-command`|Page down.| |`M-^`|`delete-indentation`|Join previous line.| |`M-- M-^`|`delete-indentation`|Join following line.| |`M-<`|`beginning-of-buffer`|Go to start of file.| |`M->`|`end-of-buffer`|Go to end of file.| |`M-{`|`backward-paragraph`|Previous paragraph.| |`M-}`|`forward-paragraph`|Next paragraph.| |`C-x C-f`|`find-file`|Find file.| |`C-x C-v`|`find-alternate-file`|Find alternative file.| |`C-x k`|`kill-buffer`|Kill current or named buffer.| |`C-x o`|`other-window`|Go to next window, split.| |`C-x O`|`other-window`|Go back to previous window, split.| |`C-x i`|`insert-file`|Insert file contents into the current file.| |`C-x h`|`mark-whole-buffer`|Highlight entire buffer.| |`C-x h, C-M-`|`indent-region`|Re-indent code region in region or from previous mark point.| |`C-x C-j`|`dired-jump`|Open Dired jump.| |`C-x SPC`|`rectangle-mark-mode`|Rectangle edit mode, can use string-insert-rectangle.| |`C-x +`|`balance-windows`|Resize all splits to equal sizes.| |`C-x 5 2`|`make-frame-command`|Open in new frame.| |`C-x r SPC`|`point-to-register`|Point-to-register.| |`C-x r j`|`jump-to-register`|Jump-to-register.| |`g`|`revert-buffer`|Refresh page, workes on many UI pages.| |`M-s o`|`occur`|List lines using regex.| |`M-s h r`|`highlight-regexp`|Highlights regex expression.| |`M-r`|`move-to-window-line-top-bottom`|Move cursor to top, middle and bottom.| |`C-l`|`recenter-top-bottom`|Move text in relation to the cursor, to top, middle and bottom.| |`M-!`|`shell-command`|Run a shell command.| |`M-&`|`async-shell-command`|Async shell command.| |`C-u 0`|`universal-argument`|Infinite count prefix.| |`C-u {count}`|`universal-argument`|Repeat operation x amount of times.| |`C-x z`|`repeat`|Repeat command.| |`C-x backspace`|`backward-kill-sentence`|Clear mini-buffer.| |`C-k C-k C-y C-y`||Duplicate line. (Place cursor at start)| |`M-g M-g`|`goto-line`|Go to line.| |`C-x b`|`switch-to-buffer`|Quick switch buffer.| |`C-x 1`|`delete-other-windows`|Kill other windows.| |`C-x s`|`save-some-buffers`|Save other buffers.| |`M-z (char)`|`zap-to-char`|Zap up to char.| |`C-M-`|`indent-region`|Re-indent region.| |`C-x * g`|`calc-dispatch`|Eval in new buffer.| |`M-<space>`|`just-one-space`|Removes extra whitespace between two words.| |`C-u M-x`|`universal-argument`|Run command with additional options.| ||`locate`|Find a files matching a pattern across the entire system.| ||`recentf`|Shows a list of recent files, if `recentf` mode is enabled.| ## Macros |Shortcut|Command Invoked|Description| |:-|:-|:-| |`C-x (`|`kmacro-start-macro`|Define keyboard macro.| |`C-x )`|`kmacro-end-macro`|End keyboard macro definition.| |`C-x e`|`kmacro-end-and-call-macro`|Playback keyboard macro, can just keep pressing `e` after first press.| |`C-x C-k <space>`|`kmacro-step-edit-macro`|Open keyboard macro debugger.| |`C-x C-k e`|`edit-kbd-macro`|Enter macro editor, (C-c C-c) to finish editing.| |`C-x C-k n`|`kmacro-name-last-macro`|Save the keyboard macro for later use.| ||`insert-kbd-macro`|Insert a saved macro into the file, in Emacs lisp.| ## Balanced Expressions |Shortcut|Command Invoked|Description| |:-|:-|:-| |`C-M-f`|`forward-sexp`|Forward over an sexps.| |`C-M-b`|`backward-sexp`|Backward over a sexps.| |`C-M-d`|`down-list`|Move down into a sexps.| |`C-M-u`|`backward-up-list`|Move up out of a sexps.| |`C-M-n`|`forward-list`|Move forward to the sexps.| |`C-M-p`|`backward-list`|Move backward to the previous sexps.| |`C-M-k`|`kill-sexp`|Kill down into sexps.| ## Incremental Search |Shortcut|Command Invoked|Description| |:-|:-|:-| |`C-M-s`|`isearch-forward-regexp`|Regex search.| |`C-s`|`isearch-forward`|Incremental search.| |`C-s C-s`|`isearch-repeat-forward`|Repeat incremental search.| |`C-s C-w`|`isearch-yank-word-or-char`|Enter incremental search and start expanding the selection.| |`C-r`|`isearch-backward`|Incremental search backward.| |`C-r C-r`|`isearch-repeat-backward`|Repeat incremental search backward.| |`C-s C-y`|`isearch-yank-kill`|Start incremental search using yanked text.| |`C-s M-y`|`isearch-yank-pop-only`|Start incremental search from kill ring string.| |`C-r`|`recursive-edit`|During query replace, enter recursive edit mode.| |`C-M-c`|`exit-recursive-edit`|During query replace, exit recursive edit mode and continue query replacement.| |`C-]`|`abort-recursive-edit`|During query replace, exit recursive edit mode and query replace modes.| |`M-s o`|`isearch-occur`|Show all lines matching the search term in occur.| |`M-s e`|`isearch-edit-string`|To edit the search string in the minibuffer.| |`M-s h r`|`isearch-highlight-regexp`|Highlights the last search string.| ## Query Replace |Shortcut|Command Invoked|Description| |:-|:-|:-| |`M-%`|`query-replace`|Start a query replace operation.| |`!`||Replace all remaining matches in this buffer with no more questions.| |`^`||Move point back to previous match.| |`u`||Undo previous replacement.| |`U`||undo all replacements.| |`E`||Edit the replacement string.| ## Tags |Shortcut|Command Invoked|Description| |:-|:-|:-| |`M-.`|`xref-find-definitions`|Jump to tag.| |`M-,`|`xref-go-back`|Jump back.| |`C-x 4 .`|`xref-find-definitions-other-window`|Visit tag in new split.| |`C-x 5 .`|`xref-find-definitions-other-frame`|Visit tag in new frame.| ## Xref |Shortcut|Command Invoked|Description| |:-|:-|:-| |`M-.`|`xref-find-definitions`|Find definitions at point.| |`M-,`|`xref-go-back`|Pop marker and return.| |`M-?`|`xref-find-references`|Find references matching a pattern.| |`C-M-.`|`xref-find-apropos`|Find symbols matching a pattern.| ## Bookmarks |Shortcut|Command Invoked|Description| |:-|:-|:-| |`C-x r m`|`bookmark-set`|Create / set bookmark.| |`C-x r b`|`bookmark-jump`|Open bookmark.| |`C-x r l`|`bookmark-bmenu-list`|List bookmarks.| ## Abbrev |Shortcut|Command Invoked|Description| |:-|:-|:-| |`C-x a g`|`add-global-abbrev`|Add global abbrev.| |`C-x a l`|`add-mode-abbrev`|Add local abbrev.| |`C-q`||Mute abbrev.| ## Ivy Buffer |Shortcut|Command Invoked|Description| |:-|:-|:-| |`S-<space>`|`ivy-restrict-to-matches`|Narrow search to current term.| |`C-M-p`|`ivy-previous-line-and-call`|Preview up.| |`C-M-n`|`ivy-next-line-and-call`|Preview down.| |`M-o`|`ivy-dispatching-done`|Open item options.| ## Occur Buffer |Shortcut|Command Invoked|Description| |:-|:-|:-| |`e`|`occur-edit-mode`|Directly edit the entry in place.| |`C-c C-c`|`occur-mode-goto-occurrence`|Return back to occur mode after edit.| ## Dired Buffer |Shortcut|Command Invoked|Description| |:-|:-|:-| |`C-o`|`dired-display-file`|Preview file but stay in Dired buffer.| |`C-u k`|`dired-do-kill-lines`|Remove section.| |`X`|`dired-do-shell-command`|Execute shell command on file.| |`Q`|`dired-do-find-regexp-and-replace`|Query replace marked files, `<space>` accept, `n` decline and `C-x s` to save all.| |`+`|`dired-create-directory`|Create directory.| |`^`|`dired-up-directory`|Go up one directory.| ||`find-name-dired`|Recursively find a file.| ## Grep Buffer |Shortcut|Command Invoked|Description| |:-|:-|:-| |`C-c C-K`|`command kill-compilation`|Kill process.| ## Compile Buffer |Shortcut|Command Invoked|Description| |:-|:-|:-| |`?`|`describe-mode`|Describe-mode.| |`g`|`recompile`|Recompile.| |`h`|`describe-mode`|Describe-mode.| |`q`|`quit-window`|Quit-window.| ||`compile`|Run one of the targets in your make file.| ## Interactively Do Things (Ido) Buffer |Shortcut|Command Invoked|Description| |:-|:-|:-| |`M-f`|`ido-wide-find-file-or-pop-dir`|Find file recursively. Search into sub directory.| |`?`|`ido-completion-help`|See a full list of all matching buffers.| |`C-j`|`ido-select-text`|Choose selected file/folder/text from minibuffer. e,g. Open folder in Dired .| ## Interface To Spell (Ispell) and On The Fly Spell (Flyspell) |Shortcut|Command Invoked|Description| |:-|:-|:-| |`M $`|`ispell-word`|Check and correct spelling of the word at point.| |`C-M i`|`completion-at-point`|Complete the word before point based on the spelling dictionary.| |`C-c $`|`flyspell-correct-word-before-point`|Correct word before point.| ||`flyspell-mode`|Enable Fly-spell mode, which highlights all misspelled words.| ||`flyspell-prog-mode`|Enable Fly-spell mode for comments and strings only.| ||`flyspell-buffer`|Check and correct spelling in the buffer.| ## Org Buffer |Shortcut|Command Invoked|Description| |:-|:-|:-| |`S-M-RET`|`org-insert-todo-heading`|Insert a new TODO entry below the current one.| |`C-c / t`|`org-match-sparse-tree`|View todo items in a sparse tree.| |`C-c C-t`|`org-todo`|Toggle todo item state.| |`C-c C-s`|`org-schedule`|Schedule todo item.| |`C-c C-d`|`org-deadline`|Add deadline to todo item.| |`C-c [`|`org-agenda-file-to-front`|Add file to agenda.| |`C-c ]`|`org-remove-file`|Remove file to agenda.| |`C-c .`|`org-timestamp`|Insert current date.| |`C-c C-e`|`org-export-dispatch`|Open exporter.| |`C-c C-e #`|`org-export-dispatch`|Insert template.| |`C-c C-e P x`|`org-export-dispatch`|Export specific project.| ## Edit I updated the list, as u/bhrgunatha helped by painstakingly adding the invoked commands for all the keyboard shortcut in the list, massive thanks to him! I think this will be the last time I update this post, for the latest version please see the GitHub repository (link above).
bobowzki · 2022-09-02 16:51
That's fantastic!
eis3nheim · 2022-09-02 17:12
This is great, definitely going to implement a lot of them in my configuration. **Thank you.**
PlatypusOrthoganus · 2022-09-02 18:27
That's cool. A few I wasn't aware of like join previous line, quit emacs, and delete following blank lines. I'll have to try those out.
livrem · 2022-09-02 19:05
I believe that C-u followed by digits is the same thing as holding Meta while pressing digits. M-- is just a special case to input a negative number (the same as C-u -). At least I have held that belief for over two decades and never noticed anything contradicting it, but maybe the two ways are sometimes not identical?
TheKrister2 · 2022-09-02 20:30
Would be nice if the function they called was noted too, for those that don't use the default keybinds.
by_wicker · 2022-09-02 20:57
Aren't these default bindings?
by_wicker · 2022-09-02 21:06
I believe you're right. Also same as `C-<digit>` and `C-M-<digit>` and `ESC <digit>`. Not sure why it's duplicated so much, but it does no harm, and means that you could consider reusing some bindings for other purposes.
copperbranch · 2022-09-02 21:35
Emacs is amazing. You have a super long list with a lot of shortcuts I didn't even know about, and yet there are a bunch I use a lot that are not in the list: - sentence-based commands: M-a, M-e, M-k, C-x DEL. (move to previous, move to next, delete to end of sentence, delete to beginning of sentence) - case commands: M-l, M-u, M-c, C-x C-l, C-x C-u (lower case, uppercase, capitalize, lower region, upper region) There are also a lot I use in org-mode I could add, I'll just mention C-x n s and C-x n w (narrow to subtree and back to everything) Sorry for the bad formatting I'm on my cellphone.
rguy84 · 2022-09-02 21:42
Looks like it to me, but I don't use every type of buffer listed
copperbranch · 2022-09-02 22:03
You could help them with that, contributing in the repository.
tmting · 2022-09-03 00:08
Maybe it's just for discoverability reasons
VernonGrant · 2022-09-03 00:18
I didn't know that, thanks!
VernonGrant · 2022-09-03 00:24
I didn't know about `C-x DEL`, but the rest I also use. Just forgot to mention them. I'll update the list. Thanks!
Hooxen · 2022-09-03 02:40
some gems in here!!
unixbhaskar · 2022-09-03 02:48
Thank you so much. Learned some new keystrokes. And bookmark it too. Appreciate.
VernonGrant · 2022-09-03 03:18
No problem!
7890yuiop · 2022-09-03 06:59
> A few I wasn't aware of like ... quit emacs :)
[deleted] · 2022-09-03 08:44
[deleted]
0xMii · 2022-09-03 08:59
I think it’s duplicated so much so it’s easy to use with all other shortcuts. If you want to do a `M-<key>` command with a prefix arg it’s as easy as holding Meta, typing the number and then the key, and the same goes for `C-<key>` commands. Switching between them is annoying and easier to mess up.
JDRiverRun · 2022-09-03 11:46
Cool trick with `C-x o` (delete-blank-lines): it can be called again immediately. First call collapses to only one blank line, next call removes all of them. Also learned about `M- M-SPACE` which obliterates all consecutive spaces and newlines but one.
TheKrister2 · 2022-09-03 15:07
Sure, I probably could, if I knew what functions the keybinds called.
[deleted] · 2022-09-04 08:47
[deleted]
TheKrister2 · 2022-09-05 06:50
I am aware of the help functions, but `describe-key`, for example, does not check both the vanilla keybind set and the current one if you've changed anything. Likewise, function names and descriptions don't always match closely enough in regard to third-party lists like from this thread, which can make them either annoying or near impossible to find.
azhake · 2022-09-08 08:29
Simpler version for `isearch-edit-string`: M-e