Dilip's Log

Emacs Efficiency

Published on

This is straight away from VernonGrant who hosts a podcast for Emacs called “Discovering-Emacs”. It’s a great and has very much professional vibes, the explanations are Crisp and Clear! I suggest you to check out, he even has made YouTube channel for it.

I have removed some of the common bindings from this table, I have retained some unique one’s which isn’t discovered generally. I guess that is why the name is made (lol)

I just wanted to have a cheatsheet for it, so I decided to leave it as a post here.

You can checkout the source here ⟾ https://github.com/VernonGrant/emacs-keyboard-shortcuts

General Shortcuts

ShortcutCommand InvokedDescription
C-x Esc Escrepeat-complex-commandEdit and re-evaluate last complex command.
C-h fdescribe-functionHelp information for a function.
C-h xdescribe-commandHelp information for a command (a function available using M-x).
C-h lview-lossageShow log for key presses and commands.
M--negative-argumentPrefix to perform negative meta commands.
C--negative-argumentPrefix to perform negative commands.
M-ldowncase-wordLowercase word forward.
M-ccapitalize-wordCapitalize word forward.
M-uupcase-wordUppercase word forward.
C-<space> C-<space>set-mark-commandAdd mark to mark ring.
C-u C-<space>set-mark-commandJump to previous mark.
M-qfill-paragraphWrap/reformat to fill column.
M-^delete-indentationJoin previous line.
M-- M-^delete-indentationJoin following line.
M-{backward-paragraphPrevious paragraph.
M-}forward-paragraphNext paragraph.
C-x C-vfind-alternate-fileFind alternative file.
C-x iinsert-fileInsert file contents into the current file.
C-x hmark-whole-bufferHighlight entire buffer.
C-M-\indent-regionRe-indent code region in region or from previous mark point.
C-x C-xexchange-point-and-markPut the mark where point is now, and point where the mark is now.
C-x C-jdired-jumpOpen Dired jump.
C-x SPCrectangle-mark-modeRectangle edit mode, can use string-insert-rectangle.
C-x +balance-windowsResize all splits to equal sizes.
C-x 5 2make-frame-commandOpen in new frame.
C-x r SPCpoint-to-registerPoint-to-register.
C-x r jjump-to-registerJump-to-register.
M-s ooccurList lines using regex.
M-s h rhighlight-regexpHighlights regex expression (useful for presentations).
M-rmove-to-window-line-top-bottomMove cursor to top, middle and bottom.
C-lrecenter-top-bottomMove text in relation to the cursor, to top, middle and bottom.
M-!shell-commandRun a shell command.
M-&async-shell-commandAsync shell command.
C-u 0universal-argumentInfinite count prefix.
C-u {count}universal-argumentRepeat operation x amount of times.
C-x zrepeatRepeat command.
C-x backspacebackward-kill-sentenceClear mini-buffer.
M-g M-ggoto-lineGo to line.
C-x 1delete-other-windowsKill other windows.
M-z (char)zap-to-charZap up to char.
C-x * gcalc-dispatchEval in new buffer.
C-u M-xuniversal-argumentRun command with additional options.

Macros

ShortcutCommand InvokedDescription
C-x (kmacro-start-macroDefine keyboard macro.
C-x )kmacro-end-macroEnd keyboard macro definition.
C-x ekmacro-end-and-call-macroPlayback keyboard macro, can just keep pressing e after first press.
C-x C-k <space>kmacro-step-edit-macroOpen keyboard macro debugger.
C-x C-k eedit-kbd-macroEnter macro editor, (C-c C-c) to finish editing.
C-x C-k nkmacro-name-last-macroSave the keyboard macro for later use.
insert-kbd-macroInsert a saved macro into the file, in Emacs lisp.

Project

ShortcutCommand InvokedDescription
C-x p !project-shell-commandRun shell-command in the current project’s root directory.
C-x p &project-async-shell-commandRun async-shell-command in the current project’s root directory.
C-x p fproject-find-fileVisit a file (with completion) in the current project.
C-x p Fproject-or-external-find-fileVisit a file (with completion) in the current project or external roots.
C-x p bproject-switch-to-bufferDisplay buffer in the selected window, for a buffer belonging to the current project.
C-x p sproject-shellStart an inferior shell in the current project’s root directory.
C-x p dproject-find-dirStart Dired in a directory inside the current project.
C-x p Dproject-diredStart Dired in the current project’s root.
C-x p vproject-vc-dirRun VC-Dir in the current project’s root.
C-x p cproject-compileRun compile in the project root.
C-x p eproject-eshellStart Eshell in the current project’s root directory.
C-x p kproject-kill-buffersKill the buffers belonging to the current project.
C-x p pproject-switch-projectSwitch to another project by running an Emacs command.
C-x p gproject-find-regexpFind all matches for REGEXP in the current project’s roots.
C-x p Gproject-or-external-find-regexpFind all matches for REGEXP in the project roots or external roots.
C-x p rproject-query-replace-regexpQuery-replace REGEXP in all the files of the project.
C-x p xproject-execute-extended-commandExecute an extended command in project root.

Balanced Expressions

ShortcutCommand InvokedDescription
C-M-fforward-sexpForward over an sexps.
C-M-bbackward-sexpBackward over a sexps.
C-M-ddown-listMove down into a sexps.
C-M-ubackward-up-listMove up out of a sexps.
C-M-nforward-listMove forward to the sexps.
C-M-pbackward-listMove backward to the previous sexps.
C-M-kkill-sexpKill down into sexps.
M-(insert-parenthesesWraps region in parenthesis.

Query Replace

ShortcutCommand InvokedDescription
M-%query-replaceStart a query replace operation.
!Replace all remaining matches in this buffer with no more questions.
^Move point back to previous match.
uUndo previous replacement.
Uundo all replacements.
EEdit the replacement string.

Xref

ShortcutCommand InvokedDescription
M-.xref-find-definitionsFind definitions at point.
M-,xref-go-backPop marker and return.
M-?xref-find-referencesFind references matching a pattern.
C-M-.xref-find-aproposFind symbols matching a pattern.

Bookmarks

ShortcutCommand InvokedDescription
C-x r mbookmark-setCreate / set bookmark.
C-x r bbookmark-jumpOpen bookmark.
C-x r lbookmark-bmenu-listList bookmarks.

Dired Buffer

ShortcutCommand InvokedDescription
C-odired-display-filePreview file but stay in Dired buffer.
C-u kdired-do-kill-linesRemove section.
Xdired-do-shell-commandExecute shell command on file.
Qdired-do-find-regexp-and-replaceQuery replace marked files, <space> accept, n decline and C-x s to save all.
+dired-create-directoryCreate directory.
^dired-up-directoryGo up one directory.
find-name-diredRecursively find a file.

Interface To Spell (Ispell) and On The Fly Spell (Flyspell)

ShortcutCommand InvokedDescription
M $ispell-wordCheck and correct spelling of the word at point.
C-M icompletion-at-pointComplete the word before point based on the spelling dictionary.
M-TABflyspell-auto-correct-wordAutomatically corrects the current word at point, will also cycle between option.
C-c $flyspell-correct-word-before-pointCorrect word before point.

Org Buffer

ShortcutCommand InvokedDescription
S-M-RETorg-insert-todo-headingInsert a new TODO entry below the current one.
C-c / torg-match-sparse-treeView todo items in a sparse tree.
C-c C-torg-todoToggle todo item state.
C-c C-sorg-scheduleSchedule todo item.
C-c C-dorg-deadlineAdd deadline to todo item.
C-c [org-agenda-file-to-frontAdd file to agenda.
C-c ]org-remove-fileRemove file to agenda.
C-c .org-timestampInsert current date.
C-c C-eorg-export-dispatchOpen exporter.
C-c C-e #org-export-dispatchInsert template.
C-c C-e P xorg-export-dispatchExport specific project.

EWW

ShortcutCommand InvokedDescription
Beww-list-bookmarksDisplay your bookmarks.
beww-add-bookmarkAdd the current page as a bookmark.
leww-back-urlGo to the previously displayed page.
reww-forward-urlGo to the next displayed page.
geww-reloadReload the current page.
GewwGo to a new address.
Heww-list-historiesShows a list of your histories.
TABshr-next-linkSkip to the next link.

Useful Commands

CommandDescription
keep-linesDelete all lines not matching the provided regex.
flush-linesDelete all lines matching the provided regex.
sort-linesSort lines in region alphabetically.
delete-duplicate-linesDelete all but one copy of any identical lines in the region.
ff-find-other-fileFind the header or source file corresponding to this file.