Skip to content

Instantly share code, notes, and snippets.

@embayer
Last active June 3, 2021 22:38
Show Gist options
  • Save embayer/d14f970c365c027db8319481a9e9a79f to your computer and use it in GitHub Desktop.
Save embayer/d14f970c365c027db8319481a9e9a79f to your computer and use it in GitHub Desktop.
emacs cheatsheet

basic operations

help

<Ctrl-h> a ....................... get help for a command (word list or regexp)
<Ctrl-h> k ....................... describe key

save

<Ctrl-x> <Ctrl-s> ................. save the current buffer
<Ctrl-x> <s> ...................... save all buffers
<Ctrl-x> <Ctrl-w> ................. save the current buffer with a specified filename

open

<Ctrl-x> <Ctrl-f> ................. open/create file
<Meta-x> revert-buffer ............ reload file in current buffer
<Meta-x> find-file-at-point ............ open a uri

close

<Ctrl-x> <Ctrl-c> ................. quit
<Ctrl-x> <k> ...................... kill buffer

copy paste

<Ctrl-w> .......................... copy
<Ctrl-y> .......................... paste
<Meta-w> .......................... cut

search and replace

<Ctrl-s> .......................... incremental search
<Ctrl-s> .......................... next candidat
<Meta-x> delete-trailing-whitespace . guess what

buffer

<Ctrl-x> <1> ...................... delete all other windows
<Ctrl-x> <o> ...................... switch buffer

source

<Ctrl-x> <Ctrl-e> ................. eval sexp

packages

<Meta-x> list-packages <Enter> .... list available packages


re-builder

<Meta-x> re-builder ................ start regular expression builder
<Ctrl-c> <Ctrl-q> .................. exit regular expression builder

evil-mode

<Meta-p> ........................... search history up
<Meta-n> ........................... search history down
/ <ctrl-y> ........................ paste text to search for

org-mode

help

cheatsheet.pdf

<Meta-x> org-info <Enter> ......... read the documentation

visibility cycling

<Tab> ............................. rotate current subtree between states
<Shift-Tab> ....................... rotate entire buffer between states

motion

<Ctrl-c> <Ctrl-n/p> ............... next/previous heading
<Meta-up> ......................... scroll to next page
<Meta-down> ....................... scroll to previous page
<Ctrl-l> .......................... focus the text around the coursor (can be repeated)

structure editing

<Meta-Shift-Up/Down> .............. move subtree/list item up/down
<Meta-Enter> ...................... insert new heading/item at current level
<Ctrl-Enter> ...................... insert new heading after subtree
<Meta-Shift-Enter> ................ insert new TODO entry (TODO || - [ ])

tables

|--<Tab> .......................... insert seperating row
<Ctrl-c> <Ctrl-c> ................. re-align the table without moving the cursor
<Tab> ............................. re-align the table, move to next field
<Shift-Tab> ....................... move to previous field
<Enter> ........................... re-align the table, move to next row
<Meta-Shift-Up/Down> .............. move row up/down
<Meta-Left/Right> ................. move the current column left
<Meta-Shift-Left> ................. kill the current column
<Meta-Shift-Right> ................ insert new column to left of cursor position
<C-u> <C-c> <|> ................... convert selected region to table

formulas

<Ctrl-c> ? ........................ reference the current cell
<Ctrl-c> } ........................ turn on the reference visualization grid
<Ctrl-u> <Ctrl-c> * ............... re-evaluate all formulas

:=vsum(@2..@9) .................... sum of row 2 -9
:=vmean($1..$9) ................... mean of column 1 - 9

links

<Ctrl-c> <Ctrl-l> ................. insert a link (TAB completes stored links) / edit link at point
<Ctrl-u> <Ctrl-c> <Ctrl-l> ........ insert file link with file name completion
<Ctrl-c> <Ctrl-o> ................. open file links in emacs
<Ctrl-c> <Ctrl-l> ................. edit link under the cursor

format

[[link][description]]       or alternatively           [[link]]

TODO Items

<Ctrl-c> <Ctrl-t> ................. rotate the state of the current item
<Shift-Up/Down> ................... raise/lower priority
<Ctrl-c> <Ctrl-c> ................. toggle checkbox at point (- [ ] subtask)
<Meta-Shift-Enter> ................ insert new TODO entry (TODO || - [ ])

timestamps

<Ctrl-c> <.> ...................... prompt for date and insert timestamp
<Ctrl-c> <Ctrl-d> ................. insert DEADLINE timestamp
<Ctrl-c> <Ctrl-s> ................. insert SCHEDULED timestamp
<Shift-Right/Left> ................ change timestamp at cursor ±1 day
<Shift-Up/Down> ................... change year/month/day at cursor by ±1
<Ctrl-c> <>> ...................... access the calendar for the current date
<Ctrl-c> <<> ...................... insert timestamp matching date in calendar access agenda for current date

agenda

<Ctrl-c> <a> <a> .................. agenda view
<l> ............................... log view
<q> ............................... quit

code blocks

<Ctrl-c> <Ctrl-c> ................ execute code block under cursor

format

#+BEGIN_SRC sh
echo "This file takes up `du -h emacs.md |sed 's/\([0-9k]*\)[ ]*emacs.md/\1/'`"
#+END_SRC

supported languages

Language Identifier Language Identifier
Asymptote asymptote Awk awk
C C C++ C++
Clojure clojure CSS css
D d ditaa ditaa
Graphviz dot Emacs Calc calc
Emacs Lisp emacs-lisp Fortran fortran
gnuplot gnuplot Haskell haskell
Java java Javascript js
LaTeX latex Ledger ledger
Lisp lisp Lilypond lilypond
MATLAB matlab Mscgen mscgen
Objective Caml ocaml Octave octave
Org mode org Oz oz
Perl perl Plantuml plantuml
Processing.js processing Python python
R R Ruby ruby
Sass sass Scheme scheme
GNU Screen screen Sed sed
shell sh SQL sql
SQLite sqlite

tags

<Ctrl-c> <Ctrl-q> ................. set tags for current heading
<Ctrl-u> <Ctrl-c> <Ctrl-q> ........ realign tags in all headings
<Ctrl-c> <\> ...................... create sparse tree with matching
<Ctrl-c> <Ctrl-o> ................. tags globally (agenda) match tags at cursor

priority

<Shift-Up/Down> ................... set prio for header

export

<Ctrl-c> <Ctrl-e> ................. export/publish dispatcher

workgroups2

<Ctrl-c> <z> ....................... <prefix>

<prefix> c ......................... create workgroup
<prefix> A ......................... rename workgroup
<prefix> k ......................... kill workgroup
<prefix> v ......................... switch to workgroup
<prefix> C-s ....................... save session
<prefix> C-f ....................... load session

helm

usage

You can mark candidates with C-SPC; this is useful when you need to perform an action on many candidates of your choice (kill buffers for example). M-a to select all. You can insert marked candidates into the current buffer with C-c C-i. This is useful when you have narrowed to a list of candidates, i.e. files, and then you want to save such candidates. If you find the current horizontal Helm window is small, you can always switch it to a vertical window with C-t. Running C-t again returns the Helm window back to horizontal and so on.

From within a helm-find-files session, you can invoke helm-ff-run-grep with C-s to search a file/directory on highlighted entry in the Helm buffer. With prefix argument C-u, recursively greps a selected directory.

You can also save the result into a Grep buffer using the action Save results in Grep buffer. Note that this Grep buffer is created by Helm, not the default Emacs grep buffer. It has minimal key bindings. In hgrep buffer, press C-h m to view all key bindings.

functions

helm-for-files
helm-complex-command-history
helm-projectile-grep
helm-info
helm-find
helm-info
helm-regexp
helm-top
helm-surfraw
helm-color
helm-eval-expression-with-eldoc
helm-calcul-expression
helm-show-kill-ring
helm-find-files             ;; like find-file-at-point
"~/tmp"

magit

<Meta-x> magit-status ....................... show magit status buffer
s	Stage current hunk	If point is in diff header, will stage all hunks belonging to current diff. If a region is active, only lines in that region will be staged. This is a distinct improvement on the conventional 'git add -p', the splitting mechanics of which are… 'imperfect'.

u Unstage current hunk As with s command, only in reverse: diff headers and regions provide a corresponding context to the unstage action. S Stage all hunks U Unstage all hunks k Discard uncommitted changes As with s command. c Prepare for commit Pops up magit-log-edit buffer. to allow you to enter your commit message. C-c C-c Execute commit Actually triggers commit action. Fire this inside the magit-log-edit commit message buffer. To postpone the commit for later, just C-x b to a different buffer and come back to this buffer when you're ready, C-c C-a Make the next commit an amend

smartparens

sp-splice-sexp .. remove surrounding

help

<Ctrl-h> a ....................... get help for a command (word list or regexp)
<Ctrl-h> k ....................... describe key
<Ctrl-h> aget help for a command (word list or regexp)
<Ctrl-h> kdescribe key

save

<Ctrl-x> <Ctrl-s> …………….. save the current buffer <Ctrl-x> <s> …………………. save all buffers <Ctrl-x> <Ctrl-w> …………….. save the current buffer with a specified filename

open

<Ctrl-x> <Ctrl-f> …………….. open/create file <Meta-x> revert-buffer ………… reload file in current buffer <Meta-x> find-file-at-point ………… open a uri

close

<Ctrl-x> <Ctrl-c> …………….. quit <Ctrl-x> <k> …………………. kill buffer

copy paste

<Ctrl-w> …………………….. copy <Ctrl-y> …………………….. paste <Meta-w> …………………….. cut

search and replace

<Ctrl-s> …………………….. incremental search <Ctrl-s> …………………….. next candidat <Meta-x> delete-trailing-whitespace . guess what

buffer

<Ctrl-x> <1> …………………. delete all other windows <Ctrl-x> <o> …………………. switch buffer

source

<Ctrl-x> <Ctrl-e> …………….. eval sexp


packages

<Meta-x> list-packages <Enter> …. list available packages



re-builder

<Meta-x> re-builder ……………. start regular expression builder <Ctrl-c> <Ctrl-q> ……………… exit regular expression builder


evil-mode

<Meta-p> ……………………… search history up <Meta-n> ……………………… search history down / <ctrl-y> …………………… paste text to search for

org-mode

help

[cheatsheet.pdf][http://orgmode.org/orgcard.pdf]] [refcard.org][https://github.com/fniessen/refcard-org-mode]]

<Meta-x> org-info <Enter> ……… read the documentation

visibility cycling

<Tab> ……………………….. rotate current subtree between states <Shift-Tab> ………………….. rotate entire buffer between states

motion

<Ctrl-c> <Ctrl-n/p> …………… next/previous heading <Meta-up> ……………………. scroll to next page <Meta-down> ………………….. scroll to previous page <Ctrl-l> …………………….. focus the text around the coursor (can be repeated)

structure editing

<Meta-Shift-Up/Down> ………….. move subtree/list item up/down <Meta-Enter> …………………. insert new heading/item at current level <Ctrl-Enter> …………………. insert new heading after subtree <Meta-Shift-Enter> ……………. insert new TODO entry (TODO || - [ ])

tables

–<Tab> …………………….. insert seperating row

<Ctrl-c> <Ctrl-c> …………….. re-align the table without moving the cursor <Tab> ……………………….. re-align the table, move to next field <Shift-Tab> ………………….. move to previous field <Enter> ……………………… re-align the table, move to next row <Meta-Shift-Up/Down> ………….. move row up/down <Meta-Left/Right> …………….. move the current column left <Meta-Shift-Left> …………….. kill the current column <Meta-Shift-Right> ……………. insert new column to left of cursor position <C-u> <C-c> <|> ………………. convert selected region to table

formulas

<Ctrl-c> ? …………………… reference the current cell <Ctrl-c> } …………………… turn on the reference visualization grid <Ctrl-u> <Ctrl-c> * …………… re-evaluate all formulas

:=vsum(@2..@9) ……………….. sum of row 2 -9 :=vmean($1..$9) ………………. mean of column 1 - 9

links

<Ctrl-c> <Ctrl-l> …………….. insert a link (TAB completes stored links) / edit link at point <Ctrl-u> <Ctrl-c> <Ctrl-l> …….. insert file link with file name completion <Ctrl-c> <Ctrl-o> …………….. open file links in emacs <Ctrl-c> <Ctrl-l> …………….. edit link under the cursor

format

description or alternatively link

Items

<Ctrl-c> <Ctrl-t> …………….. rotate the state of the current item <Shift-Up/Down> ………………. raise/lower priority <Ctrl-c> <Ctrl-c> …………….. toggle checkbox at point (- [ ] subtask) <Meta-Shift-Enter> ……………. insert new TODO entry (TODO || - [ ])

timestamps

<Ctrl-c> <.> …………………. prompt for date and insert timestamp <Ctrl-c> <Ctrl-d> …………….. insert DEADLINE timestamp <Ctrl-c> <Ctrl-s> …………….. insert SCHEDULED timestamp <Shift-Right/Left> ……………. change timestamp at cursor ±1 day <Shift-Up/Down> ………………. change year/month/day at cursor by ±1 <Ctrl-c> <>> …………………. access the calendar for the current date <Ctrl-c> <<> …………………. insert timestamp matching date in calendar access agenda for current date

agenda

<Ctrl-c> <a> <a> ……………… agenda view <l> …………………………. log view <q> …………………………. quit

code blocks

<Ctrl-c> <Ctrl-c> ……………. execute code block under cursor

format

echo "This file takes up `du -h emacs.md |sed 's/\([0-9k]*\)[ ]*emacs.md/\1/'`"

supported languages

LanguageIdentifierLanguageIdentifier
AsymptoteasymptoteAwkawk
CCC++C++
ClojureclojureCSScss
Ddditaaditaa
GraphvizdotEmacs Calccalc
Emacs Lispemacs-lispFortranfortran
gnuplotgnuplotHaskellhaskell
JavajavaJavascriptjs
LaTeXlatexLedgerledger
LisplispLilypondlilypond
MATLABmatlabMscgenmscgen
Objective CamlocamlOctaveoctave
Org modeorgOzoz
PerlperlPlantumlplantuml
Processing.jsprocessingPythonpython
RRRubyruby
SasssassSchemescheme
GNU ScreenscreenSedsed
shellshSQLsql
SQLitesqlite

tags

<Ctrl-c> <Ctrl-q> …………….. set tags for current heading <Ctrl-u> <Ctrl-c> <Ctrl-q> …….. realign tags in all headings <Ctrl-c> <\> …………………. create sparse tree with matching <Ctrl-c> <Ctrl-o> …………….. tags globally (agenda) match tags at cursor

priority

<Shift-Up/Down> ………………. set prio for header

export

<Ctrl-c> <Ctrl-e> …………….. export/publish dispatcher

workgroups2

<Ctrl-c> <z> ………………….. <prefix>

<prefix> c ……………………. create workgroup <prefix> A ……………………. rename workgroup <prefix> k ……………………. kill workgroup <prefix> v ……………………. switch to workgroup <prefix> C-s ………………….. save session <prefix> C-f ………………….. load session

helm

usage

You can mark candidates with C-SPC; this is useful when you need to perform an action on many candidates of your choice (kill buffers for example). M-a to select all. You can insert marked candidates into the current buffer with C-c C-i. This is useful when you have narrowed to a list of candidates, i.e. files, and then you want to save such candidates. If you find the current horizontal Helm window is small, you can always switch it to a vertical window with C-t. Running C-t again returns the Helm window back to horizontal and so on.

From within a helm-find-files session, you can invoke helm-ff-run-grep with C-s to search a file/directory on highlighted entry in the Helm buffer. With prefix argument C-u, recursively greps a selected directory.

You can also save the result into a Grep buffer using the action Save results in Grep buffer. Note that this Grep buffer is created by Helm, not the default Emacs grep buffer. It has minimal key bindings. In hgrep buffer, press C-h m to view all key bindings.

functions

helm-for-files helm-complex-command-history helm-projectile-grep helm-info helm-find helm-info helm-regexp helm-top helm-surfraw helm-color helm-eval-expression-with-eldoc helm-calcul-expression helm-show-kill-ring helm-find-files ;; like find-file-at-point “~/tmp”

magit

<Meta-x> magit-status ………………….. show magit status buffer s Stage current hunk If point is in diff header, will stage all hunks belonging to current diff. If a region is active, only lines in that region will be staged. This is a distinct improvement on the conventional ‘git add -p’, the splitting mechanics of which are… ‘imperfect’. u Unstage current hunk As with s command, only in reverse: diff headers and regions provide a corresponding context to the unstage action. S Stage all hunks U Unstage all hunks k Discard uncommitted changes As with s command. c Prepare for commit Pops up magit-log-edit buffer. to allow you to enter your commit message. C-c C-c Execute commit Actually triggers commit action. Fire this inside the magit-log-edit commit message buffer. To postpone the commit for later, just C-x b to a different buffer and come back to this buffer when you’re ready, C-c C-a Make the next commit an amend

sp-splice-sexp .. remove surrounding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment