Skip to content

Instantly share code, notes, and snippets.

@peterhil
Created March 17, 2025 00:12
Show Gist options
  • Save peterhil/fb268d2f5ecfd3765b08c907f4333767 to your computer and use it in GitHub Desktop.
Save peterhil/fb268d2f5ecfd3765b08c907f4333767 to your computer and use it in GitHub Desktop.
Custom macOS keybindings – Emacs and tenkeyless keyboards like Keychron K7
/* ~/Library/KeyBindings/DefaultKeyBinding.dict
Custom macOS keybindings – universal Emacs bindings and helpers
for tenkeyless keyboards like Keychron K7.
This file remaps the key bindings of a single user on Mac OS X.
Here is a rough cheatsheet for syntax.
Key Modifiers
^ : Ctrl
$ : Shift
~ : Option (Alt)
@ : Command (Apple)
# : Numeric Keypad
Non-Printable Key Codes
Standard
Up Arrow: \UF700 Backspace: \U0008 F1: \UF704
Down Arrow: \UF701 Tab: \U0009 F2: \UF705
Left Arrow: \UF702 Escape: \U001B F3: \UF706
Right Arrow: \UF703 Enter: \U000A ...
Insert: \UF727 Page Up: \UF72C
Delete: \UF728 Page Down: \UF72D
Home: \UF729 Print Screen: \UF72E
End: \UF72B Scroll Lock: \UF72F
Break: \UF732 Pause: \UF730
SysReq: \UF731 Menu: \UF735
Help: \UF746
OS X
Delete: \U007F
For reference see:
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html
Based on:
https://gist.github.com/trusktr/1e5e516df4e8032cbc3d
https://gist.githubusercontent.com/trusktr/1e5e516df4e8032cbc3d/raw/ab7c868a8354219782b37971f984564c66a53d78/DefaultKeyBinding.dict
*/
{
/* Additional Emacs bindings */
"~f" = "moveWordForward:";
"~b" = "moveWordBackward:";
"~<" = "moveToBeginningOfDocument:";
"~>" = "moveToEndOfDocument:";
"~v" = "pageUp:";
"~d" = "deleteWordForward:";
"~^h" = "deleteWordBackward:";
"~\010" = "deleteWordBackward:"; /* Option-backspace */
"~\177" = "deleteWordForward:"; /* Option-delete */
/* Escape should really be complete: */
"\033" = "complete:"; /* Escape */
/* Multikey Emacs bindings */
"\033" = {
"\033" = "complete:"; /* ESC-ESC */
"f" = "moveWordForward:"; /* ESC-f */
"b" = "moveWordBackward:"; /* ESC-b */
"<" = "moveToBeginningOfDocument:"; /* ESC-< */
">" = "moveToEndOfDocument:"; /* ESC-> */
"v" = "pageUp:"; /* ESC-v */
"d" = "deleteWordForward:"; /* ESC-d */
"^h" = "deleteWordBackward:"; /* ESC-Ctrl-H */
"\010" = "deleteWordBackward:"; /* ESC-backspace */
"\177" = "deleteWordForward:"; /* ESC-delete */
};
/* My bindings */
/* Keychron K7 and other tenkeyless keyboards */
"~\UF729" = "moveToEndOfDocument:"; /* Option + Home */
/* Convenience */
"@~j" = ("moveUp:","moveUp:","moveUp:","moveUp:","moveUp:","moveUp:","moveUp:","moveUp:",); /* Cmd + Option + j */
"@~k" = ("moveDown:","moveDown:","moveDown:","moveDown:","moveDown:","moveDown:","moveDown:","moveDown:",); /* Cmd + Option + k */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment