Skip to content

Instantly share code, notes, and snippets.

@kingslayer
Last active November 30, 2021 23:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kingslayer/540cd2dad583d1b5563f173995385d00 to your computer and use it in GitHub Desktop.
Save kingslayer/540cd2dad583d1b5563f173995385d00 to your computer and use it in GitHub Desktop.
read2text test

KeyBinding madness

Theres a somewhat mysterious individual who is consistently leaving brilliant little pieces of code and information in my comments. Dr. Drang has been visited by this apparition as well. Were both duly impressed with what he (or she?) does.

So, Im digging through the code Lris posted and I find a DefaultKeyBinding.dict file. Its the best one Ive ever seen, and it inspires me to do some fiddling of my own. I figured Id post my result, but with due credit to Lri (hi, Lri!).

The DefaultKeyBinding.dict file tells your computer at a fairly root level how to handle keyboard shortcuts in input fields. It doesnt work everywhere, but sometimes its surprising where it does work. In those cases, you can save yourself a ton of time by committing a few custom keystrokes to memory.

You may be familiar with the basic Emacs keybindings that are default (Ctrl-a beginning of line, Ctrl-e end of line, etc.), but this allows you to go much further. For more information, check out Macworld hints, an older but very relevant article from Harvard and do a search for more information.

Basically, all you need to do is put the DefaultKeyBinding.dict file into ~/Library/KeyBindings and restart applications you want it to work in. Edit away, and change shortcuts to things youre comfortable with. Several of mine are sequences which allow groupings, which I like, but you might not. Be aware that these can be a little unpredictable as to when theyll override a system/application default and when theyll be overridden (I know theres a logic to it, I just dont want to dive into that).

Ive posted my KeyBindings on GitHub and included a cheatsheet in MultiMarkdown as well as a Readme with the tables already rendered. Direct download link below. If youre looking for something to nerd out on this weekend, this should whet your appetite.

Killer DefaultKeyBinding.dict v1.0

Download Killer DefaultKeyBinding.dict v1.0

A custom DefaultKeyBinding.dict file which adds shortcuts for document navigation, Markdown and much more. Inspired by Lri.

Updated Sat Aug 13 2011.

More info…

Just for reference, heres the table of shortcuts in the KeyBindings file:

Grouped items begin with the groups shortcut, followed by the Keys specified. Items separated by commas are sequential, not concurrent.

All purpose key combos

Group Keys Function

Opt-z copy character before cursor

Opt-r repeat character before cursor

Opt-t transpose characters

Opt-+ uppercase word

Opt- lowercase word

Opt-. capitalize word

Ctrl-w delete word before cursor

Opt-w select word

Opt-f cut word (fold)

Opt-g copy word (grab)

Opt-h paste word (hit)

Opt-l select entire line/paragraph

Opt-s select from beginning of paragrah to last character

Opt-d delete line/paragraph

Opt-y copy paragraph

Opt-x cut paragraph

Opt-p paste paragraph below

Opt-Shift-P paste paragraph above

Ctrl-Shift-A select to beginning of paragraph and copy

Ctrl-Shift-E select to end of paragraph and copy

Opt-q cut to beginning of paragraph

Opt-k cut to end of paragraph

Opt-, move paragraph up a line, inserting blank space after

Opt- move paragraph to end of document

Opt-o blank line after current

Opt-Shift-O blank line before current

Cmd-Opt-/ comment with //

Cmd-Opt-3 comment with #

Markdown-specific shortcuts (Ctrl-Cmd-W)

Group Keys Function

Cmd-Opt-b bold selection

Cmd-Opt-i italicize selection

Ctrl-Cmd-w Return force Return

Ctrl-Cmd-w Tab force Tab

Ctrl-Cmd-w 14

Headlines

Ctrl-Cmd-w l,t link text "[selected text](|)"

Ctrl-Cmd-w l,c clipboard link "[|selected text](clipboard contents)"

Ctrl-Cmd-w i,t image, selection as alt "![selected text](|)"

Ctrl-Cmd-w i,c clipboard image "![|selected text](clipboard contents)"

Ctrl-Cmd-w :,t create a reference from selected text

Ctrl-Cmd-w :,c create a reference from selected text, clipboard as url

Ctrl-Cmd-w [ insert reference link

Ctrl-Cmd-w +|-|* lists

Opt-Shift-L new list item after current

Ctrl-Cmd-w e entity

Ctrl-Cmd-w / http://

Surround (Ctrl-Cmd-s)

Group Keys Function

Ctrl-Cmd-s ( wrap () with spaces

Ctrl-Cmd-s ) wrap () no spaces

Ctrl-Cmd-s [ wrap [] with spaces

Ctrl-Cmd-s ] wrap [] no spaces

Ctrl-Cmd-s { wrap {} with spaces

Ctrl-Cmd-s } wrap {} no spaces

Ctrl-Cmd-s < wrap <> with spaces

Ctrl-Cmd-s

wrap <> no spaces

Ctrl-Cmd-s wrap single quotes

Ctrl-Cmd-s ` wrap backticks

Ctrl-Cmd-s " wrap double quote

List/Paragraph motion

Group Keys Function

Ctrl-Cmd-k move line up

Ctrl-Cmd-j move line down

Ctrl-Cmd-l indent line

Ctrl-Cmd-h outdent line (all the way)

Ctrl-Opt-k copy line and paste above

Ctrl-Opt-j copy line and paste below

Cmd-Opt-Up modify selection up

Cmd-Opt-Down modify selection down

Cmd-Del Forward delete to end of paragraph

Group Keys Function

PgUp Page Up

PgDown Page Down

Opt-PgUp Scroll up

Opt-PgDown Scroll Down

Opt-1 bookmark

Opt-2 jump to bookmark

Follow the author on Twitter and App.net.
This content is supported by readers like you.

Topics: keybindings, keyboard, osx

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