Skip to content

Instantly share code, notes, and snippets.

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 */
Copy link

lenalebt commented Dec 18, 2019

I switched from Linux to a Mac for work (Linux was not available), but at home I'm still using Linux. Everything is fine BUT THE KEYBOARD LAYOUT and there is no easy standard setting to simply get a german windows keymapping (no dead keys) on a mac.

I am using this gist to document how to get near a standard german windows keyboard layout using whatever tools seem necessary. That being said, I know that there is a tool called "Ukulele" ( which might do a better job than what I did now. If you used Ukulele and created a fully functional keyboard layout, feel free to share it!

First, swap CTRL and CMD (I'll call it SUPER, which will be your windows key on an external windows keyboard) by navigating to the mac settings:
This already makes it possible to use CTRL+C / CTRL+V to copy/paste. However, killing a task in a terminal now moves to SUPER+C.

Then, use the attached DefaultKeybinding.dict and put it in ~/Library/KeyBindings. This file takes care to map jumping over words with CTRL-ARROW (normally, this works via OPTION/ALT+ARROW on a mac) and enables usage of HOME, END, PGUP, PGDN and so on. However, due to whatever limitations I'm not aware of, this does not work in all applications, but most will accept it. I used this blog post as a guide to create the file:

What's missing now is the mappings of parantheses, pipe symbol, the @ sign, tilde and so on. For that, you can use a tool called "karabiner elements", which you can get via brew cask install karabiner-elements. Install it, then navigate to Complex modifications -> Rules -> Add Rule:
Now click on "import more rules from the internet (open a web brwoser)" which will take you here: Import these rules:

See the above picture to see which exact rules you need to activate. I did not activate most of the PC Shortcuts because they have been changed through the key bindings file already.

Why did I not use karabiner-elements for all the other mappings? Because it fucks up some of the bindings and, depending on the ordering of the rules, behaves differently- I was not able to map the "jump over words" with karabiner, so I only use it for as much as I really need it. Most importantly: I could not get the mappings to work correctly in IntelliJ (most notably: HOME/END and jumping over words).

Now, I still had problems with the window management since I frequently switch windows with the keyboard, and there is no such thing as a keyboard shortcut that cycles all windows. You have a shortcut to cycle applications (now: SUPER-TAB) and one that cycles windows of the same applications (it was: CMD+<, but I cannot find it currently). To get a "cycle through all windows", you need a tool called "hyperswitch": brew cask install hyperswitch. Set it up this way:

To get snappy edges to arrange your windows, I tried a few tools. "hyperdock" seems to want to do what need, but it crashes and does not work reliably. You can try your luck: brew cask install hyperdock with the following settings:

Moving windows with ALT+LEFT MOUSE and resizing them via ALT+RIGHT MOUSE is possible via "Easy Move+Resize" which can be installed with brew cask install easy-move-plus-resize. Settings:

Now, almost everything should work already the way you are used to. There are a few minor quirks that you can solve, e.g. I always close my IntelliJ by accident since I have "quick documentation" mapped to CTRL-Q which now behaves as "Quit application". You can solve this by adding a keyboard shortcut in the mac keyboard settings: System Preferences -> Keyboard -> Shortcuts

Oh, and I set all IntelliJ settings in the keymap manually. But that is different for everyone, so I don't think it makes sense to share it here.

List of things that do not work (yet):

  • no dead keys (ukulele should be able to solve this, but have not tried yet)
  • maybe more, give feedback :)

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 🎉

Copy link

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.

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.

Copy link

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

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.

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