Skip to content

Instantly share code, notes, and snippets.

@trusktr
Last active April 21, 2024 06:32
Show Gist options
  • Save trusktr/1e5e516df4e8032cbc3d to your computer and use it in GitHub Desktop.
Save trusktr/1e5e516df4e8032cbc3d to your computer and use it in GitHub Desktop.
My DefaultKeyBinding.dict for Mac OS X
/* ~/Library/KeyBindings/DefaultKeyBinding.Dict
This file remaps the key bindings of a single user on Mac OS X 10.5 to more
closely match default behavior on Windows systems. This makes the Command key
behave like Windows Control key. To use Control instead of Command, either swap
Control and Command in Apple->System Preferences->Keyboard->Modifier Keys...
or replace @ with ^ in this file.
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 a good reference see http://osxnotes.net/keybindings.html.
NOTE: typically the Windows 'Insert' key is mapped to what Macs call 'Help'.
Regular Mac keyboards don't even have the Insert key, but provide 'Fn' instead,
which is completely different.
*/
{
"@\UF72B" = "moveToEndOfDocument:"; /* Cmd + End */
"~@\UF703" = "moveToEndOfDocument:"; /* Cmd + Option + Right Arrow */
"@$\UF72B" = "moveToEndOfDocumentAndModifySelection:"; /* Shift + Cmd + End */
"@\UF729" = "moveToBeginningOfDocument:"; /* Cmd + Home */
"~@\UF702" = "moveToBeginningOfDocument:"; /* Cmd + Option + Left Arrow */
"@$\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Cmd + Home */
"\UF729" = "moveToBeginningOfLine:"; /* Home */
"~\UF702" = "moveToBeginningOfLine:"; /* Option + Left Arrow */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"$~\UF702" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Option + Right Arrow */
"\UF72B" = "moveToEndOfLine:"; /* End */
"~\UF703" = "moveToEndOfLine:"; /* Option + Right Arrow */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */
"$~\UF703" = "moveToEndOfLineAndModifySelection:"; /* Shift + Option + Left Arrow */
"\UF72C" = "pageUp:"; /* PageUp */
"\UF72D" = "pageDown:"; /* PageDown */
"$\UF728" = "cut:"; /* Shift + Del */
"$\UF727" = "paste:"; /* Shift + Ins */
"@\UF727" = "copy:"; /* Cmd + Ins */
"$\UF746" = "paste:"; /* Shift + Help */
"@\UF746" = "copy:"; /* Cmd + Help (Ins) */
"~j" = "moveBackward:"; /* Option + j */
"~l" = "moveForward:"; /* Option + l */
"~i" = "moveUp:"; /* Option + i */
"~k" = "moveDown:"; /* Option + k */
"@~i" = ("moveUp:","moveUp:","moveUp:","moveUp:","moveUp:","moveUp:","moveUp:","moveUp:",); /* Cmd + Option + j */
"@~k" = ("moveDown:","moveDown:","moveDown:","moveDown:","moveDown:","moveDown:","moveDown:","moveDown:",); /* Cmd + Option + j */
"@\UF702" = "moveWordBackward:"; /* Cmd + LeftArrow */
"@~j" = "moveWordBackward:"; /* Cmd + Option + j */
"@\U007F" = "deleteWordBackward:"; /* Cmd + Backspace */
"@\UF703" = "moveWordForward:"; /* Cmd + RightArrow */
"@~l" = "moveWordForward:"; /* Cmd + Option + l */
"@\UF728" = "deleteWordForward:"; /* Cmd + Delete */
"@$\UF702" = "moveWordBackwardAndModifySelection:"; /* Shift + Cmd + Leftarrow */
"@$\UF703" = "moveWordForwardAndModifySelection:"; /* Shift + Cmd + Rightarrow */
}
@jlahijani
Copy link

"^\UF702" = "moveWordLeft:"; // ctrl-left
"^\UF703" = "moveWordRight:"; // ctrl-right

This doesn't work on BigSur. Anyone know the correct way?

@jace
Copy link

jace commented Jul 9, 2021

"^\UF702" = "moveWordLeft:"; // ctrl-left
"^\UF703" = "moveWordRight:"; // ctrl-right

This doesn't work on BigSur. Anyone know the correct way?

@jlahijani These have changed to moveWordBackward and moveWordForward.

@pmunin
Copy link

pmunin commented Feb 9, 2022

was moveToBeginningOfDocument changed to something also for Big Sur? Ctrl + Home/End does not work for me from that:

"^\UF729" = "moveToBeginningOfDocument:"; /* Ctrl + Home */
"^\UF72B" = "moveToEndOfDocument:"; /* Ctrl + End */

@mrjoecastellon
Copy link

Working perfectly on MacOS Monterey 12.0.1

Thank you!

@mrjoecastellon
Copy link

"^\UF702" = "moveWordLeft:"; // ctrl-left
"^\UF703" = "moveWordRight:"; // ctrl-right

This doesn't work on BigSur. Anyone know the correct way?

@jlahijani These have changed to moveWordBackward and moveWordForward.

Odd. Those work for me on Monterey without changing "left" or "right" to "backward" / "forward"

🤔

@srsudar
Copy link

srsudar commented Mar 26, 2022

Is there a way to enter escape? I'd like to globally remap ctrl+[ to escape without downloading something as heavyweight as Karabiner.

I've tried various combinations of:

"^[" = "\U001B";
"^[" = ("insertText:", "\U001B");

I don't see escape listed here as an option.

Does anyone know if there's another way to do that?

@lotyp
Copy link

lotyp commented Apr 17, 2022

Can't find "space" key anywhere 😀 For example Cmd+Space to trigger Spotlight.

Upd. ok, will try to go with U+0020 \U0020

@mrjoecastellon
Copy link

Can't find "space" key anywhere 😀 For example Cmd+Space to trigger Spotlight.

Upd. ok, will try to go with U+0020 \U0020

Thanks for updating when you found the code!

Did it work for you?

@lotyp
Copy link

lotyp commented Apr 21, 2022

No, also tried to go with \040 which mac sees as Space, but it does not work when I set it through console:

defaults write "Apple Global Domain" NSUserKeyEquivalents -dict-add "System Preferences\\U2026" "@$\040"

If I choose other char than space, then hotkeys are working...

image

Found spacebar character here:

https://github.com/ttscoff/KeyBindings/blob/master/DefaultKeyBinding.dict

Edit:

🎉🎉🎉

Works:

Just an example: (Shift + Cmd + Space)

defaults write com.apple.universalaccess com.apple.custommenu.apps -array NSGlobalDomain
defaults write "Apple Global Domain" NSUserKeyEquivalents -dict-add "System Preferences\\U2026" "@$\U0020"

@mrjoecastellon
Copy link

No, also tried to go with \040 which mac sees as Space, but it does not work when I set it through console:

defaults write "Apple Global Domain" NSUserKeyEquivalents -dict-add "System Preferences\\U2026" "@$\040"

If I choose other char than space, then hotkeys are working...

image

Found spacebar character here:

https://github.com/ttscoff/KeyBindings/blob/master/DefaultKeyBinding.dict

Edit:

🎉🎉🎉

Works:

Just an example: (Shift + Cmd + Space)

defaults write com.apple.universalaccess com.apple.custommenu.apps -array NSGlobalDomain defaults write "Apple Global Domain" NSUserKeyEquivalents -dict-add "System Preferences\\U2026" "@$\U0020"

Cool find!! Thank you so much for sharing!

@LeeBinder
Copy link

LeeBinder commented May 12, 2022

Does anybody know how I can toggle the keyboard command for the (floating) application switcher (in Windows: Alt + Tab) from ⌘⇥ (Cmd + Tab) to ⌃⇥ (Ctrl. + Tab)? The corresponding line would be:

"^\U0009" = "???:"; // application switcher

The question is: what to enter as correct identifier instead of ???

@TwiggyWan
Copy link

TwiggyWan commented Nov 5, 2022

Does anybody know how I can toggle the keyboard command for the (floating) application switcher (in Windows: Alt + Tab) from ⌘⇥ (Cmd + Tab) to ⌃⇥ (Ctrl. + Tab)? The corresponding line would be:

"^\U0009" = "???:"; // application switcher

The question is: what to enter as correct identifier instead of ???

Dunno how to do it through the dict, but you could use https://alt-tab-macos.netlify.app/ then customize the shortcut in this program's preferences.

@LeeBinder
Copy link

Thanks @TwiggyWan for the pointer. I had lost sight of AltTab and thanks to your link see that it's in constant development.

@esstein
Copy link

esstein commented Jan 18, 2023

Does DefaultKeyBinding.dict works on MacOS 13 Ventura ???

@mrjoecastellon
Copy link

Yes it does, but it's worth mentioning that in pretty much all MacOS versions, there are some applications where the keybindings either work in part or not at all.

@esstein
Copy link

esstein commented Jan 18, 2023

Yes it does, but it's worth mentioning that in pretty much all MacOS versions, there are some applications where the keybindings either work in part or not at all.

Yes, it really works. I reprogram the key cmd+e and it is default to find selection on Ventura. I change the key and it's working now. Thanks

@alvister88
Copy link

I'm trying to use "^\U007F" = "deleteWordBackward:"; // ctrl-backspace and it works for most apps. However, in apps such as google docs and vscode, I think something overrides this hotkey and doesn't work. Does anyone know a solution to this issue?

@evannjohnson
Copy link

I'm finding that the Option+i to move up shortcut is not working, the shortcut seems to be overridden by something that is inserting a caret. I'm having trouble identifying where this shortcut is defined so I can disable it. Any ideas?

@smitty-codes
Copy link

smitty-codes commented Jul 25, 2023

I'm trying to use "^\U007F" = "deleteWordBackward:"; // ctrl-backspace and it works for most apps. However, in apps such as google docs and vscode, I think something overrides this hotkey and doesn't work. Does anyone know a solution to this issue?

@alvister88 Regarding Visual Studio for Mac and Visual Studio Code, they both have their own set of key bindings you need to fix separately since they don't seem to inherit everything from the DefaultKeyBinding.Dict file.

Here are VSC's default key bindings

In particular I am a heavy user of the "home" and "end" keys in VSC and the CTRL+Home and CTRL+End navigating to the top and bottom of the document was not working so I did the following steps:

  1. Open VSC > Code menu > Preferences > Keyboard editor (also see https://code.visualstudio.com/docs/getstarted/keybindings)
  2. Search for “cursorTop” and “cursorBottom” (the entries with "When=textInputFocus") and you can right click on one of these existing entries > "add keybinding..." and then add your new shortcut and it'll clone it.

I didn't check how to do this within VS for Mac but I'm sure there are similar settings.

@gopycode
Copy link

I'm finding that the Option+i to move up shortcut is not working, the shortcut seems to be overridden by something that is inserting a caret. I'm having trouble identifying where this shortcut is defined so I can disable it. Any ideas?

@evannjohnson I don't think that's re-mappable: That's for attaching an accent to a character, and it's not in the StandardKeyBinding file. It's pre-OS X.

@lotyp and @mrjoecastellon:

Can't find "space" key anywhere 😀 For example Cmd+Space to trigger Spotlight.

Upd. ok, will try to go with U+0020 \U0020

Just use the characters if they're printable. defaults write -g NSUserKeyEquivalents -dict-add "System Preferences…" "^ "

A couple other things to make life easier:

  • -g above is shorthand for the global domain
  • You can use defaults write -app Safari … (or whatever).

@joaobcjr
Copy link

joaobcjr commented Jan 7, 2024

In a text file with 3 rows, when I use "Shift + Up Arrow" in the middle of the second row to select the first one, when I try "Shift + End" to deselect, it goes on the line below.
How do I reproduce windows actions in this case?

Here's some examples:

This is what is happening
https://gist.github.com/assets/37077552/89db4553-1c3e-465b-a6ce-052ff822d88c

This is what I trying to reproduce
https://gist.github.com/assets/37077552/1e1516a2-0247-4c73-a6f9-8f51c254bb85

@hym3242
Copy link

hym3242 commented Jan 14, 2024

Is there any way we can get this to affect the Chrome omnibox and all <textarea> elements? They support the opt+ctrl+b/f to jump by word but lack ctrl+opt+h to deletewordbackward.

@hym3242
Copy link

hym3242 commented Jan 14, 2024

Is there a moveParagraphForward action? I tried to set it to no avail. This should be what opt+downarrow do.

@hym3242
Copy link

hym3242 commented Jan 14, 2024

@joaobcjr It indeed is weird, but i don't think there's anything we can do....

@hym3242
Copy link

hym3242 commented Jan 14, 2024

using FileMonitor from objective-see we know that Chrome indeed reads DefaultKeyBinding.dict and actually uses them everywhere from omnibox to <textarea> !!!

@hym3242
Copy link

hym3242 commented Jan 15, 2024

see my dump of standardkeybinding.dict and AppKit symbols for bindable methods, maybe you will get some new ideas
https://gist.github.com/hym3242/8e8bc10a2fed8e55973c500f1798c234

@hym3242
Copy link

hym3242 commented Jan 19, 2024

here is my binding: explore for more yourself.

{
        "^~h" = "deleteWordBackward:"; //bash style...
        "^~d" = "deleteWordForward:"; //ibid
        "^u" = "deleteToBeginningOfParagraph:"; //unix style kill, ONLY THIS METHOD deleteToBeginningOfParagraph: CAN ADD SELECTION TO YANK BUFFER!(or so it seems...)
        "^w" = "deleteWordBackward:"; //unix style werase
        "~a" = "selectParagraph:"; //cocoa paragraph ≈ unix line
        "^m" = "insertNewline:";  //RETURN as in "Carriage Return"
        "^j" = "insertNewlineIgnoringFieldEditor:"; //default also bound to opt+return, alternate newline, bypasses some editor smart features
        "~v" = "pageUp:"; //you know your emacs.
        "~V" = "pageUpAndModifySelection:";  //shift+option+v
        "~A" = "selectWord:";
        "~c" = "capitalizeWord:";  //uppercaseWord: method does  not seem to work?
        "~t" = "convertToTraditionalChinese:"; //convert selection
        "~s" = "convertToSimplifiedChinese:"; //ibid.
        "^J" = "insertLineBreak:";  //linebreak is different from newline. default also bound to ctrl+return

// add these to your liking
//      "~h" = "deleteWordBackward:";
//      "~d" = "deleteWordForward:";
//      "~b" = "moveWordBackward:";
//      "~f" = "moveWordForward:";
}

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