Skip to content

Instantly share code, notes, and snippets.

@mkleehammer
Created April 23, 2024 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkleehammer/d91f5b35496a8ceab680ab9c553d211b to your computer and use it in GitHub Desktop.
Save mkleehammer/d91f5b35496a8ceab680ab9c553d211b to your computer and use it in GitHub Desktop.
Emacs Keybinding Organization

Key Bindings

Core

C-/undo
C-Z or C-M-_redo
C-x =position infoincludes column info

Windows & Buffers

C-o C-oconsult-buffer
M-oother-window
C-o <n>Switch to window n
C-o fflip windows
C-o rrotate windows
C-x C-jjump to file in dired

Movement

M-a & M-emove by sentence
M-{ & M-}move by paragraph
M-g M-ggoto line
M-g lavy goto line
M-iavy goto word 2
C-;goto last change
C-iimenu
M-g p & M-g nprevious / next error
M-n & M-pnext / previous flycheck error
M-s . or C-M-sisearch symbol [1]
C-M-a & C-M-eforward / back function
C-M-f & C-M-bforward / back expressionmatch parens
C-M-n & C-M-pnext / previous expressionsame level
C-M-uup out of expressiongoto parent
C-M-ddown into expression
C-M-kkill expression
M-kkill dwimcombobulate mode only
M-S-m M-Msave point in registeremulate vim m
M-S-j M-Jjump to registeremulate vim ’

[1] In isearch, C-w copies current word into search. C-M-w copies current symbol. So, to search a symbol, assuming you are at the beginning of it, you can C-s C-M-w which is surprisingly quick.

Mark

C-SPCpush mark activate
C-M-S-SPC [1]push mark no activate
C-u C-SPC [2]pop mark (go back)
C-x C-xexchange point and mark
M-@mark to end of word
C-M-.mark whole symbolcustom
C-M-lmark whole linecustom
M-hmark whole paragraph
C-M-SPCmark expression (also C-M-@)
C-M-hmark function
C-x hmark buffer
C-M-ymark last pastecustom
C-’ [3]expand regionpackage
C-”contract regionpackage
C-x SPCrectangle mark mode

[1] This could be a good candidate or C-. which seems very point related. I’ve chosen this because it is related to C-u C-SPC which you’d use to come back to the mark.

[2] Because set-mark-command-repeat-pop is t, subsequent C-SPC presses (without C-u) will continue to pop the mark.

[3] Combobulate mode replaces this with its own expand region, so the behavior may be different between text and programming modes.

Clipboard

C-wkill region or line [1]
M-wcopy region or line [1]
C-yyank
M-yyank-pop or browse kill ring [2]
C-S-Delkill whole linecan also use C-w
M-kkill sentencetaken over by combobulate
C-x Delkill to beginning of sentence
M-zkill to charinclusive
M-Zkill up to charexclusive
C-c ffile-info-showfile-info - has commands for copying buffer name, etc.

[1] We’re using whole-line-or-region, so C-w and M-w will kill or copy the entire line if nothing is selected. This is super handy when you get used to it. They also take numeric arguments, so C-u 3 M-w copies three lines.

[2] M-y after C-y starts cycling through the kill ring. Recent Emacs versions allow you to press M-y first and browse the kill ring.

Copying the current filename

These copy commands are used in buffers associated with a file. They don’t (yet) work in dired. They start with ‘y’ like C-y and like Spacemacs, Doom, and our vi keys.

C-c y yfully qualified path
C-c y nfilename only
C-c y ddirectory
C-c y Yproject relative path
C-c y Dproject relative directory

Editing

S-returnopen below
M-S-returnopen above
C-M-S-o or C-x C-odelete blank lines
M-”surround
C-x Tab or M-S-iindent rigidly

iedit

C-M-S-iieditagain to complete
C-c frestrict to functioncustom
C-c lrestrict to linecustom
C-’show only matching lines

Org Mode

Move to Heading

I think we should map the sexp keys to heading movement keys.

up
C-c C-u
prev/next, all levels
C-c C-n/p
back/forward, same level
C-c C-b/f

Working with Subtrees

promote / demote subtree, including children
M-S-left/right
promote / demote node, not children
M-left/right
move
M-S-up/down
mark
C-c @
kill / copy
C-c C-x C-w/M-w
narrow to subtree
C-x n s
archive subtree
C-x C-c C-s

I had to remap something to moving a subtree up and down. M-S-up normally drags a single line up. That isn’t something I want to do, so I’ve remapped it. I could have used C-S-up/down which is only for modifying timestamps, but M-S matches the promote / demote so it will help me remember it.

Tables

re-align table
C-c C-c

SQL

start sql
C-c ns (new sql buffer) - I’m not liking the ‘n’
associate with buffer
C-c s

There is nothing bound to C-c s and C-c C-s is only used in org mode for scheduling. SQL buffers are important enough to us that we could use either of these.

Miscellaneous

C-h x
describe for command; doesn’t show functions
open url
M-g x
messages buffer
C-h e (echo area messages)

Potential Keys

To help organize keys into mnemonic groups and see what is available, I’m maintaining the current bindings here.

The custom column is populated if it is not a standard Emacs binding. It has the word “custom” if it is a custom binding to an existing Emacs function or a custom function in init.el. Otherwise it is the name of the package the command comes from, whether I bound it or it is a package default.

Key Bindings By Modifier

C

KeyBindingsCustomAvailable
C-SPCset mark
C-@set mark
C-]abort recursive edit
C-”contract regionexpand-region
C-’expand regionexpand-region
C-.binky-gobinky
C-,binky-addbinky
C-< (C-S-,)<
C- > (C-S-.)>
C-;goto changegotochg
C-/undo
C-?redo
C-a - C-hstandard keys
C-iavy word 2avy
C-jnewline and indentj
C-k - C-lstandard keys
C-mnewline
C-nstandard key
C-owindow keymap
C-p - C-ystandard keys
C-zz

M

KeyBindingCustomAvailable
M-SPCcycle spacing
M-!shell command
M-”surroundsurround
M-’eat (terminal)eat
M-$ispell word
M-%query replace
M-&async shell command
M-(insert parens(
M-)move past close and re-indent)
M-,xref go back
M-.xref goto def
M-/dabbrev expand
M-:eval-expression
M-;comment
M-?xref find references
M-@mark word
M-\delete horizontal space
M-^delete indentation
M-`Is Alt-tab on my keyboard
M-a - M-fstandard keys
M-gprefix
M-hmark paragraph
M-iavy word 2avy
M-j - M-mstandard keys
M-oother windowcustom
M-p - M-ystandard keys
M-zzap to char

M-S

Most of these are available.

KeyBindingsCustomAvailable
M-S-RETopen abovecustom
M-S-a - M-S-ha-h
M-S-iindent rigidlycustom
M-S-j - M-S-wj-w
M-S-xextended command for buffer
M-S-ymy-clean-copycustom
M-S-zzap up tocustom

[1] This is the same as M-j but seems easier to press. I might migrate to this and free up M-j.

*** C-S

I’m pretty sure these are available.

KeyBindingsCustomAvailable
C-S-SPCSPC
C-S-.
C-S-,
C-S-; C-:flyspell:
C-S-BSdelete whole line
C-S-a - C-S-ra-r
C-S-sconsult lineconsult
C-S-t - C-S-yt-y
C-S-zredocustom

C-M

I’d like to use these for sexp, point, and marking related functions.

KeyBindingsCustomAvailable
C-M-SPCmark sexp
C-M-@mark sexp
C-M-’
C-M-”
C-M-,xref go forward
C-M-.my mark symbolcustom
C-M-/dabbrev expand all/ ?
C-M-0 - 9goto tab bar tabcustom
C-M-abeginning of function
C-M-bbackward sexp
C-M-cexit recursive edit
C-M-ddown list
C-M-eend of function
C-M-fforward sexp
C-M-gg
C-M-hmark function
C-M-iflyspelli
C-M-jdefault indent new linej ?
C-M-kkill sexp
C-M-lmark linecustom
C-M-mevilmi-jump-items-nativeevil-matchit
C-M-nforward list
C-M-osplit lineo
C-M-pbackward list
C-M-qindent-pp-sexpq
C-M-risearch backward regexp
C-M-sisearch symbol at pointcustom
C-M-ttranspose sexps
C-M-ubackward up list
C-M-vscroll other window
C-M-wappend next kill
C-M-xeval-defun
C-M-ymark yankmark-yank
C-M-zz

C-M-S

KeyBindingsCustomAvailable
C-M-S-SPCpush mark no activatecustom
C-M-S-a
C-M-s-iiedit modeiedit
C-M-S-lrecenter other window
C-M-S-odelete blank linescustom
C-M-S-vscroll other window down

C-c

KeyBindingsCustomAvailable
C-c ’poporg
C-c aalign & app prefixcustom
C-c iinsert prefix
C-c lorg store link
C-c oorg commands
C-c nnew prefix
C-c ttoggle prefix
C-c ycopy prefixcustom

Align and App

KeyBindingsCustomAvailable
C-c a =align assignmentscustom
C-c a mapp - notmuch (mail)custom
C-c a walign whitespacecustom

Insert

KeyBindingsCustomAvailable
C-c i Tinsert time
C-c i dinsert date
C-c i rinsert random number
C-c i tinsert timestamp
C-c i uinsert UUID

New

KeyBindingsCustomAvailable
C-c n nnew buffercustom
C-c n snew SQL buffercustom

Toggles

KeyBindingsCustomAvailable
C-c t ccolor identifiers modecustom
C-c t hauto highlight symbol modecustom
C-c t n ntoggle line numbers
C-c t n rtoggle relative line numbersq

Key Bindings By Character

There are some characters that have a ton of bindings, so it helps to see them to keep them straight.

I

KeyBindingsCustomAvailable
C-iimenucustom
M-iavy goto word 2avy
C-M-iflyspell autocorrect wordC-M-i
C-S-iC-S-i
M-S-iindent rigidlycustom
C-M-S-iieditcustom

The three I set are all mnemonic and are all things I use very often. imenu is a primary means of navigation for me.

O

KeyBindingsCustomAvailable
C-oprefix
M-oother windowcustom
C-M-osplitlineC-M-o ?
C-S-oC-S-o
M-S-oM-S-o
C-M-S-odelete blank linescustom

I’ve chosen M-o for other window because it is one of the most convenient keys and is mnemonic with other-window.

Switching buffers (consult buffer) is similar, so it seemed natural to add an easy modifier shift for it.

I set delete blank lines because it is normally C-x C-o, so some ‘o’ seemed best. The default key is a bit harder to hit when typing properly and switching hands for control. And I use it a lot.

Symbols

Symbols on the Planck QWERTY layer: SPC ;’,./

SPC

KeyBindingsCustomAvailable
C-SPCset mark
M-SPCcycle spacing
C-M-SPCmark sexp
C-S-SPCC-S-SPC
C-M-S-SPCpush mark no activatecustom

1Password registers C-S-SPC as a hotkey at the OS level, but I’ve turned that off.

;

KeyBindingsCustomAvailable
C-;goto last changegotochg
M-;comment dwimwhole line or region
C-S-; C-:flyspell correct previous
C-M-;C-M-;
M-S-; M-:eval expressioncustom
C-M-S-; C-M-:C-M-:

KeyBindingsCustomAvailable
C-’expand regionexpand-region
M-’eat (terminal)eat
C-S-’ C-”contract regionexpand-region
C-M-’C-M-’
M-S-’ M-”surroundsurround
C-M-S-’ C-M-”C-M-”

,

KeyBindingsCustomAvailable
C-,binky-addbinky
M-,xref go back
C-M-,xref go forwardC-M-,
C-S-, C-<C-<
M-S-, M-<beginning of buffer
C-M-S-, C-M-<C-M-<

.

KeyBindingsCustomAvailable
C-.binky-gobinky
M-.xref goto def
C-M-.my mark symbolcustom
C-S-. C- >C-S-.
M-S-. M- >beginning of buffer
C-M-S-. C-M- >C-M-S-.

The bindings with ‘>’ have a space to keep them from turning into ligature arrows.

/

KeyBindingsCustomAvailable
C-/undo
M-/dabbrev expand
C-M-/dabbrev expand all?
C-S-/ C-?undo redo
M-S-/ M-?xref find references
C-M-S-/ C-M-?C-M-?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment