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 */
}
@ficus

This comment has been minimized.

Copy link

ficus commented Oct 26, 2016

Nice mappings. I'm having no luck getting this to work on Sierra. Have you been able to get it to work?

@mavichow

This comment has been minimized.

Copy link

mavichow commented Nov 29, 2016

no luck geting this to work on Sierra +1

@alexhayes

This comment has been minimized.

Copy link

alexhayes commented Dec 14, 2016

Likewise, doesn't seem to work on Sierra.

@alexhayes

This comment has been minimized.

Copy link

alexhayes commented Dec 14, 2016

While it's probably not the solution folks are looking for I ended up doing this in Keyboard Maestro.

@unboxedsolutions

This comment has been minimized.

Copy link

unboxedsolutions commented Dec 22, 2016

Keyboard Maestro was a great suggestion, it is working well for me. I miss Karabiner but this will do for now

@ggriffin

This comment has been minimized.

Copy link

ggriffin commented Jul 26, 2017

Using ~/Library/KeyBindings/DefaultKeyBinding.Dict to remap key bindings works for me under Sierra (10.12.5). Restarting a given app is required for the changes to take effect.

@ataiya

This comment has been minimized.

Copy link

ataiya commented Mar 21, 2018

@ggriffin have you tested this in HighSierra as well?

@agnz

This comment has been minimized.

Copy link

agnz commented Mar 28, 2018

I can confirm - works on HighSierra.

@thu-san

This comment has been minimized.

Copy link

thu-san commented Apr 30, 2018

Working on HighSierra on mine too

@mayqueen91

This comment has been minimized.

Copy link

mayqueen91 commented Jun 25, 2018

works well for HighSierra! I was a bit confused that I need to create directory KeyBindings by myself, but it worked! And now I can use both cmd+c and ctrl+c. This is great, previously "Copy link" buttons didn't work for me and now they do! THANK YOU.

@andrewdbate

This comment has been minimized.

Copy link

andrewdbate commented Jul 12, 2018

Also working on High Sierra for me -- thanks!! I prefer using these mappings over Karabiner elements because Karabiner elements screws with VMware Fusion and this does not.

@manolodeinternet

This comment has been minimized.

Copy link

manolodeinternet commented Aug 26, 2018

Beautiful presentation of the code !!!

Have any of you had any problems for overload any shortcut with any application (for changing the system default keybindings) ?

Thanks !!!

@fredrikaverpil

This comment has been minimized.

Copy link

fredrikaverpil commented Jan 20, 2019

This is what did (macOS Mojave):

{
    "~[" = (insertText:, "å");
    "~{" = (insertText:, "Å");
    "~'" = (insertText:, "ä");
    "~\"" = (insertText:, "Ä");
    "~;" = (insertText:, "ö");
    "~:" = (insertText:, "Ö");
}
@aserrallerios

This comment has been minimized.

Copy link

aserrallerios commented Apr 9, 2019

Where can I find the full reference of actions, like "moveToBeginningOfLineAndModifySelection"?

Thanks!

@phcamargo23

This comment has been minimized.

@phcamargo23

This comment has been minimized.

Copy link

phcamargo23 commented Apr 23, 2019

Following the suggestion of the author, switching Command by Control is a good one, however, to switch between applications and between guides got boring. Has anyone managed to solve this?

@Ogglord

This comment has been minimized.

Copy link

Ogglord commented May 20, 2019

Works great in Mojave 10.14.5 - lifesaver :)

@franksands

This comment has been minimized.

Copy link

franksands commented May 21, 2019

Not working for me :( I'm on Mojave 10.14.5 with a Microsoft Designer Keyboard and Brazilian layout (ABNT2)

@Ogglord

This comment has been minimized.

Copy link

Ogglord commented May 22, 2019

Not working for me :( I'm on Mojave 10.14.5 with a Microsoft Designer Keyboard and Brazilian layout (ABNT2)

Did you follow the instructions properly? Go to Library folder in your home folder, not the library folder in the root. Create the folder KeyBindings and the file "DefaultKeyBinding.Dict", case sensitive. Then it should work. I have a Func Mechanical KB with Swedish layout (Pro)

@franksands

This comment has been minimized.

Copy link

franksands commented May 22, 2019

Did you follow the instructions properly? Go to Library folder in your home folder, not the library folder in the root. Create the folder KeyBindings and the file "DefaultKeyBinding.Dict", case sensitive. Then it should work. I have a Func Mechanical KB with Swedish layout (Pro)

I indeed had copied to the Library folder in the root. It did work now! Thanks

@Walternate1

This comment has been minimized.

Copy link

Walternate1 commented Jun 3, 2019

10.14.5 (18F132) - Home/End to the beginning/end of the line is not working for me using the Mac base mail compose window, TextEdit, or in this message box. Does this work for you all in these situations?

@ryukoposting

This comment has been minimized.

Copy link

ryukoposting commented Jun 13, 2019

Hint for people having problems: there are some unicode quotes mixed in with the ASCII quotes in the gist! I'm not sure if that's what fixed it for me, but I did replace the unicode quotes with ASCII quotes (among other things):

{
//  "^c"       = "copy:"; // ctrl-c
//  "^v"       = "paste:"; // ctrl-v
//  "^x"       = "cut:"; // ctrl-x
//  "^z"       = "undo:"; // ctrl-z
//  "^y"       = "redo:"; // ctrl-y
//  "^a"       = "selectAll:"; // ctrl-a
//  "^s"       = "saveDocument:"; // ctrl-s
//  "^$s"      = "saveDocumentAs:"; // ctrl-shift-s
//  "^n"       = "newDocument:"; // ctrl-n
//  "^o"       = "openDocument:"; // ctrl-o
//  "^p"       = "printDocument:"; // ctrl-p
  "\UF729"   = "moveToBeginningOfParagraph:"; // home
  "\UF72B"   = "moveToEndOfParagraph:"; // end
  "$\UF729"  = "moveToBeginningOfParagraphAndModifySelection:"; // shift-home
  "$\UF72B"  = "moveToEndOfParagraphAndModifySelection:"; // shift-end
  "^\UF729"  = "moveToBeginningOfDocument:"; // ctrl-home
  "^\UF72B"  = "moveToEndOfDocument:"; // ctrl-end
  "^\UF702"  = "moveWordLeft:"; // ctrl-left
  "^\UF703"  = "moveWordRight:"; // ctrl-right
  "^$\UF702" = "moveWordLeftAndModifySelection:"; // ctrl-shift-left
  "^$\UF703" = "moveWordRightAndModifySelection:"; // ctrl-shift-right
  "^$\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; // ctrl-shift-home
  "^$\UF72B" = "moveToEndOfDocumentAndModifySelection:"; // ctrl-shift-end
}
@elevenfive

This comment has been minimized.

Copy link

elevenfive commented Sep 4, 2019

Truly, from the bottom of my heart, THANK YOU for sharing this. In concert with a fix for home/end in terminal, I can feel my once incredible pain when forced to use Mac OS slowly melting away.

@Rodrirokr

This comment has been minimized.

Copy link

Rodrirokr commented Sep 19, 2019

Working in Catalina (10.15 Beta) with no problem.

@raphaelsantos

This comment has been minimized.

Copy link

raphaelsantos commented Oct 6, 2019

Exactly what I was looking for, can't wait to test it. Thanks for sharing this.

@nicovs

This comment has been minimized.

Copy link

nicovs commented Oct 11, 2019

awesome!
Typing an IP on a keyboard with numpad was never this easy (since i switched from Windows to Mac :p)

{
   "#," = ("insertText:", ".");
}
@rolandas-valantinas

This comment has been minimized.

Copy link

rolandas-valantinas commented Dec 19, 2019

Any way to make following work in terminal? Works everywhere great, but in terminal it does nothing except making some error noise or smth while using shortcuts. Thanks!

"@\UF702" = moveWordBackward:;          /* Cmd  + LeftArrow */
"@\UF703" = moveWordForward:;             /* Cmd  + RightArrow */
@packetx27

This comment has been minimized.

Copy link

packetx27 commented Dec 22, 2019

How do you replace simulate CMD-F with CTRL-F to search in a document or webpage.

I've tried this :

"^f" = "search:"; // ctrl-f

but it is not working. I need the right keyword in place of search. Thank you. 👍

@rolandas-valantinas

This comment has been minimized.

Copy link

rolandas-valantinas commented Dec 23, 2019

How do you replace simulate CMD-F with CTRL-F to search in a document or webpage.

I've tried this :

"^f" = "search:"; // ctrl-f

but it is not working. I need the right keyword in place of search. Thank you. 👍

Why wouldn't you swap key modifier instead? If you after using PC layout first thing to do is to make ctrl behave as cmd in Keyboard > modifier keys. After this fewer remaps are required.
This way ctrl+[c,x,v,f,s] on pc keyboard works as you expect

@packetx27

This comment has been minimized.

Copy link

packetx27 commented Dec 23, 2019

How do you replace simulate CMD-F with CTRL-F to search in a document or webpage.
I've tried this :
"^f" = "search:"; // ctrl-f
but it is not working. I need the right keyword in place of search. Thank you. 👍

Why wouldn't you swap key modifier instead? If you after using PC layout first thing to do is to make ctrl behave as cmd in Keyboard > modifier keys. After this fewer remaps are required.
This way ctrl+[c,x,v,f,s] on pc keyboard works as you expect

I've tried but it doesn't meet my needs, because when I'm on the terminal, I do alot of CTRL+A, CTRL+E etc to move the cursor at the beginning of line, end of line, etc. Replacing CTRL by CMD via Key modifier intercept all those command line combinaisons.

@rolandas-valantinas

This comment has been minimized.

Copy link

rolandas-valantinas commented Dec 24, 2019

I've tried but it doesn't meet my needs, because when I'm on the terminal, I do alot of CTRL+A, CTRL+E etc to move the cursor at the beginning of line, end of line, etc. Replacing CTRL by CMD via Key modifier intercept all those command line combinaisons.

Gotcha - try this. Keyboard > Shortcuts > App Shortcuts > add for all applications > menu title Find... > Keyboard shortcut ^F. It works for all the app using Find... as a menu option

@packetx27

This comment has been minimized.

Copy link

packetx27 commented Dec 25, 2019

I've tried but it doesn't meet my needs, because when I'm on the terminal, I do alot of CTRL+A, CTRL+E etc to move the cursor at the beginning of line, end of line, etc. Replacing CTRL by CMD via Key modifier intercept all those command line combinaisons.

Gotcha - try this. Keyboard > Shortcuts > App Shortcuts > add for all applications > menu title Find... > Keyboard shortcut ^F. It works for all the app using Find... as a menu option

Thank you it worked! I wasn't aware of that trick, I've just mapped several shorcuts in others applications too!

@Jcode2020

This comment has been minimized.

Copy link

Jcode2020 commented Jan 3, 2020

Hi, I have created a file with
{ "\UF729" = "moveToBeginningOfParagraph:"; // home "\UF72B" = "moveToEndOfParagraph:"; // end }

I'm really new to Mac but I think it is the right folder username/Library/KeyBindings/DefaultKeyBinding.dict because my Logitech keyboard gets confused when I log off and on (e.g. scrolling direction gets inverted).

Can you please help me?

@rolandas-valantinas

This comment has been minimized.

Copy link

rolandas-valantinas commented Jan 3, 2020

Hi, I have created a file with
{ "\UF729" = "moveToBeginningOfParagraph:"; // home "\UF72B" = "moveToEndOfParagraph:"; // end }

I'm really new to Mac but I think it is the right folder username/Library/KeyBindings/DefaultKeyBinding.dict because my Logitech keyboard gets confused when I log off and on (e.g. scrolling direction gets inverted).

Can you please help me?

It's not gonna work if you put everything on one line - everything starting with home is a comment resulting in } being commented and breaking file. Try:

{ 
  "\UF72B" = "moveToEndOfParagraph:";       /* end */
  "\UF729" = "moveToBeginningOfParagraph:"; /* home */
}
@Jcode2020

This comment has been minimized.

Copy link

Jcode2020 commented Jan 3, 2020

@rolandas-valantinas

This comment has been minimized.

Copy link

rolandas-valantinas commented Jan 6, 2020

Thank you very much! Unfortunately, it still doesn't work. Any other ideas? Rolandas Valantinas notifications@github.com schrieb am Fr., 3.

Each application has to be completely restarted (some has to be force quit) to use new shortcuts. I've tested these key bindings in notes app and it works as expected

@rolandas-valantinas

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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.

@slacker-king

This comment has been minimized.

Copy link

slacker-king 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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

scottschup commented Mar 21, 2020

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

@rolandas-valantinas

This comment has been minimized.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.