Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 */
}
@rolandas-valantinas
Copy link

rolandas-valantinas commented Jan 24, 2020

Not working anymore on Catalina 10.15.2 (see here)

Don't post misguided information! Maybe that particular scenario doesn't work, but DefaultKeyBinding.dict is still a valid solution for global key remap

@floatingpurr
Copy link

floatingpurr commented Jan 27, 2020

Not working anymore on Catalina 10.15.2 (see here)

Don't post misguided information! Maybe that particular scenario doesn't work, but DefaultKeyBinding.dict is still a valid solution for global key remap

Turns out it was just a local problem of mine. It works properly also on Catalina 10.15.2

@Jcode2020
Copy link

Jcode2020 commented Jan 27, 2020

Thank you very much, it works out for me as well. Turned out, the file ending *.txt was still omitted.

@chris-tietgen
Copy link

chris-tietgen commented Feb 5, 2020

This is my first Mac (Catalina 10.15.2) and some of the built in keys were driving me crazy after using Windows for decades, so I found this today and it's very helpful. However, while it mostly works, I have run into a few issues.

For example, the END key does take me to the end of the line, but the HOME key takes me to the top of the page/document, instead of the beginning of the line. Well, some times END does what it's supposed to, but not always. Sometimes I have to press the key twice. The first time scrolls, the 2nd moves to the end of the line.

OPTION + LEFT navigates left per work and doesn't take me to the beginning of the line.

I restarted the computer, but still the same issues. Any way to fix these issues?

@Jcode2020
Copy link

Jcode2020 commented Feb 8, 2020

I'm trying to use
"~7" = ("insertText:", "{");

to mimic Windows' AltGr-Key (I have also switched CMD and CTRL). Unfortunately, it's not working. Am I missing something?

@bernardodesousa
Copy link

bernardodesousa commented Feb 13, 2020

Is there an exhaustive list of available commands for us to assign in this file? I'm looking for something like "switchWindows" to be assigned to Alt+Tab. The line "~\U0009" = "switchWindows:"; does not work on Catalina, probably because the function doesn’t exist or has a different name.

@Jcode2020
Copy link

Jcode2020 commented Feb 13, 2020

I started off with KeyBindings to get the typing straight but realized that for me it only works for the Shift, Pos1, End stuff.
Windows key combo (D, E, 1...0, arrows) I bought BetterTouchTool in combination with BetterSnapTool
For switch windows with Alt+Tab I bought Witch because even though BetterTouchTool supports switching programs (MacOS default) it does not support switching windows which eventually drove me nuts.

@scottschup
Copy link

scottschup commented Mar 21, 2020

The link in line 35 is dead, BTW http://osxnotes.net/keybindings.html

@rolandas-valantinas
Copy link

rolandas-valantinas commented Mar 25, 2020

The link in line 35 is dead, BTW http://osxnotes.net/keybindings.html

https://web.archive.org/web/20161220060333/http://osxnotes.net/keybindings.html

@ricardoaponte
Copy link

ricardoaponte commented Sep 24, 2020

Just tried it in Catalina and works like a charm! Thanks!

@georgenica
Copy link

georgenica commented Dec 30, 2020

Any idea on how to get this to work on BigSur (11.1)? The dictionary file is no longer accessible at that path on the filesystem.

@rolandas-valantinas
Copy link

rolandas-valantinas commented Jan 5, 2021

Any idea on how to get this to work on BigSur (11.1)? The dictionary file is no longer accessible at that path on the filesystem.

I don't think Catalyst apps support usage of that file https://www.reddit.com/r/mac/comments/jv97u8/catalyst_apps_ignore_defaultkeybindingdict/

@floatingpurr
Copy link

floatingpurr commented Jan 5, 2021

Oh! So, no key binding is possible on BigSur?

@philipchristopher
Copy link

philipchristopher commented Jan 14, 2021

Oh! So, no key binding is possible on BigSur?

This worked for me on BigSur 11.1:

mkdir -p $HOME/Library/KeyBindings
echo '{
/* Remap Home / End keys to be correct */
"\UF729" = "moveToBeginningOfLine:"; /* Home */
"\UF72B" = "moveToEndOfLine:"; /* End */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */
"^\UF729" = "moveToBeginningOfDocument:"; /* Ctrl + Home */
"^\UF72B" = "moveToEndOfDocument:"; /* Ctrl + End */
"$^\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Ctrl + Home */
"$^\UF72B" = "moveToEndOfDocumentAndModifySelection:"; /* Shift + Ctrl + End */
}' > $HOME/Library/KeyBindings/DefaultKeyBinding.dict

Original thread: https://discussions.apple.com/thread/251108215

FYI, it saves the file in this location: /users/{YOUR_USERNAME}/Library/KeyBindings/DefaultKeyBinding.dict

@JorgeLuisCampos
Copy link

JorgeLuisCampos commented Feb 7, 2021

Oh! So, no key binding is possible on BigSur?

Yes, it works!

@louisdeb
Copy link

louisdeb commented Apr 11, 2021

This still works in BigSur. If ~/Library/KeyBindings/DefaultKeyBinding.dict, create the directory and the file. New key bindings won't work in already running apps - you'll need to restart the app.

@Geru-Scotland
Copy link

Geru-Scotland commented May 24, 2021

Do anyone know what code is used for right Command and Option? I would like to remap right cmd as "Home" and right Option as "End", but can't find the proper codes. Using Key Codes doesn't seem to work, unfortunately.

@louisdeb
Copy link

louisdeb commented May 25, 2021

~ : Option (Alt)
@ : Command (Apple)

Maybe they're reserved. Also remember to restart the app you're trying testing it in.

@Geru-Scotland
Copy link

Geru-Scotland commented May 25, 2021

~ : Option (Alt)
@ : Command (Apple)

Maybe they're reserved. Also remember to restart the app you're trying testing it in.

Thank you for your answer. I meant the right Command and Option, I mean, I can not find a way to identify when those keys have been specifically pressed. I would like to bind Right Cmd and Right Option and leave the left ones as they are right now.

@jlahijani
Copy link

jlahijani commented Jul 9, 2021

"^\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

mrjoecastellon commented Mar 22, 2022

Working perfectly on MacOS Monterey 12.0.1

Thank you!

@mrjoecastellon
Copy link

mrjoecastellon commented Mar 22, 2022

"^\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

mrjoecastellon 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

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

mrjoecastellon 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"

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 ???

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