Skip to content

Instantly share code, notes, and snippets.

@lenalebt
Created December 18, 2019 06:59
Show Gist options
  • Save lenalebt/64d5ea94d6077a5becd00c33d0514cac to your computer and use it in GitHub Desktop.
Save lenalebt/64d5ea94d6077a5becd00c33d0514cac to your computer and use it in GitHub Desktop.
How to use a typical Linux / Windows Keybindung on MacOS (tested with 10.15.2 Catalina)
/*
PUT THIS FILE IN ~/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 particular mapping assumes
that you have also switched the Control and Command keys already.
This key mapping is more appropriate after switching Ctrl for Command in this menu:
Apple->System Preferences->Keyboard & Mouse->Keyboard->Modifier Keys...->
Change Control Key to Command
Change Command key to Control
This applies to OS X 10.5 and possibly other versions.
Here is a rough cheatsheet for syntax.
Key Modifiers
^ : Ctrl
$ : Shift
~ : Option (Alt)
@ : Command (Apple)
# : Numeric Keypad
Non-Printable Key Codes
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
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.
*/
{
"\UF729" = "moveToBeginningOfLine:"; /* Home */
"@\UF729" = "moveToBeginningOfDocument:"; /* Cmd + Home */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"$@\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Cmd + Home */
"\UF72B" = "moveToEndOfLine:"; /* End */
"@\UF72B" = "moveToEndOfDocument:"; /* Cmd + End */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */
"$@\UF72B" = "moveToEndOfDocumentAndModifySelection:"; /* Shift + Cmd + End */
"^\UF702" = "moveToBeginningOfLine:"; /* Home */
"^\UF703" = "moveToEndOfLine:"; /* End */
"$^\UF703" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */
"$^\UF702" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"\UF72C" = "pageUp:"; /* PageUp */
"\UF72D" = "pageDown:"; /* PageDown */
"@x" = "cut:"; /* Shift + Del */
"@v" = "paste:"; /* Shift + Help */
"@c" = "copy:"; /* Cmd + Help (Ins) */
"@\UF702" = "moveWordBackward:"; /* Cmd + LeftArrow */
"@\UF703" = "moveWordForward:"; /* Cmd + RightArrow */
"@$\UF702" = "moveWordBackwardAndModifySelection:"; /* Shift + Cmd + Leftarrow */
"@$\UF703" = "moveWordForwardAndModifySelection:"; /* Shift + Cmd + Rightarrow */
"@\UF728" = "deleteWordForward:"; /* Cmd + Delete */
"@\U007F" = "deleteWordBackward:"; /* Cmd + Backspace */
}
@funnierinspanish
Copy link

I've been trying to do this for a long time, thanks to your gist I managed to finally get my keyboard working the way I want 🎉

@lenalebt
Copy link
Author

lenalebt commented May 7, 2020

Hey, thank you for your feedback, that really means a lot to me :).
I did not write this down here yet, but I changed my approach in the meantime a bit. I used "Ukulele" to generate a keyboard map, and now I do have "nodeadkeys" working as well. Without going too much into detail right now, this is roughly what changed by doing so in contrast to the above:

  • no karabiner elements anymore
  • I got rid of hyperdock, since it crashed from time to time and I did not want to invest time finding out why

Maybe I'll share my keyboard maps that I created some time over here as well (but I am currently not on that machine). Ukulele took some time to get used to for me though.

@dsvyrjm
Copy link

dsvyrjm commented Nov 7, 2020

Thanks for this manual @lenalebt
I was looking how to remap Option+arrow to Cmd+arrow for quite a long. I read about the approach with DefaultKeyBinding.dict on stackoverflow but had no idea about possible key codes.
Also, It worth to add that it not need to restart/logout your Mac after edit DefaultKeyBinding.dict. It applied right after you press "save". Never-less it need to fully quit and open again target application to apply changes. For example I saw changes only after reopen Notes app.
To make this works In Intellij 2020.2 I was need to edit 4 mappings: "Move caret to next/prev word", "Move caret to line end/start".
And regards switching between apps. I love AltTab app. It free and open source and provides very convenient way to navigate through the opened windows.

@lenalebt
Copy link
Author

Hey, thanks for pointing me to AltTab, I'll try that out :-)

@JonathanDotCel
Copy link

Thanks, I didn't have time to set up a full Ukelele profile and this covers the basics quite nicely!
Note: On my Catalina install I just had to log out and uncheck "reopen my windows" for the changes to apply globally.

@towhans
Copy link

towhans commented Apr 8, 2022

Thank you for writing this. I used Ukelele.

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