How to use Windows keyman on Mac and in your favorite IDE for example IntelliJ?

Why? An example would be working on a multi-platform system where one needs to deal with Linux, Windows, and Mac. Having a common hotkey mapping will remove the friction; get the edge on efficiency; reduce the learning curve and use more ergonomic tooling interfaces across platforms.

There are the following problems out of the box:

1. Mac hotkeys are different compared to Windows
1.1 Control (Win) aka. Command (Mac) is not on the bottom right edge.
1.2 There is a third key on mac. Ctrl, Alt vs Control, Option, Command

Indeed due to Win and Mac hotkey differences, the Mac Intellij keymap is as well different.

2. IDE such as IntelliJ Mac hotkey is very different
2.1 How to find Windows keymap in IntelliJ on Mac?
2.2 How to solve the problem with the Karabiner elements?
2.3 Conflicting keymaps with Mac internal shortcuts

1.1 Changing keymapping in on Mac

Many most used commands in Windows and Linux rely on the key on the bottom right edge: The Crtl key. Therefore pinky copy paste.

On the Mac be default thump copy-paste is used so: Command + c. etc.

Easy! Just change the mapping from Mac Preferences. Could vary across the versions but for v11+ would work as follows.

System Preferences ->
Keyboard (tab) ->
Modifier Keys ->
Select keyboard

Whoila! You got your pinky copy instead of a thump copy. Something You would use out of the box on the Win and Linux systems.

1.2 On the Mac there is one more modifier key.

It is used across the OS. On windows, the keyboard is usually replaced by the windows key that open the program search. I believe it is the very reason why the IDE key mapping are different across the platforms,

2.1 How to find a Windows keymapping in Intellij?

Obviously, IntelliJ provides several choices. But one would not be able to find a keymap that provides the same Windows keymap experience.

One could find the XWin keymap under the plugin marketplace search.

Problem with IntelliJ’s XWin keymap on Mac

2.1.a The familiar Ctrl key is not on the most right bottom corner as We have swapped copy-paste in the Mac to have a pinky copy paste.

How can we do that? We can go to the keymap editor in the IDE and change every key with control to meta. It will take forever. Can we change the config file in the file system? Find replace for example? Here is how we are able to do it:

We can fix with replacing control with meta in XWin keymap
https://gist.github.com/vikreinok/69e18a79d08db956db4b56a9ae2feb91

Now, where we can find the keymap config file in Mac?

How to change the file manually:
First, we use a local repository to store the settings.
File → Manage IDE Settings → Settings repository

When you will copy the XWin keymap, you will give it your name. XWin copy for example. Where are you able to find this custom copy?
/Users/username/Library/Application Support/JetBrains/IntelliJIdea2021.1/settingsRepository/repository/keymaps

2.1.b The Familiar Alt key is not leftmost to the Space key.

Check out point 1.1 in this article that describes how to remap keys in Mac

2.2 Alt + any other key produces as a symbol.

So, the leftmost… The closest key to space with a combination of many other keys produces a symbol. Something you have might have experienced on Windows with Alt Gr + number on keypad for example. Now, why it is a problem? It conflicts with the most used IntelliJ key mappings on Mac.

2.2.a To counter that we need to install Karabiner elements

https://karabiner-elements.pqrs.org/docs/getting-started/installation/

2.2.b Edit a rule file [2]
/Users/username/.config/karabiner/karabiner.json and added your own rule in that JSON under:
profiles > complex_modifications > rules:

{
"description": "ctrl/command swap",
"manipulators": [
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.jetbrains\\.intellij$"
],
"type": "frontmost_application_unless"
}
],
"from": {
"key_code": "left_control"
},
"to": [
{
"key_code": "left_command"
}
],
"type": "basic"
},
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.jetbrains\\.intellij$"
],
"type": "frontmost_application_unless"
}
],
"from": {
"key_code": "left_command"
},
"to": [
{
"key_code": "left_control"
}
],
"type": "basic"
}
]
}

2.3 Conflicting keymaps with Mac and how to fix them

Of course, as you might expect there are some side effects when using your own super customized keyset. Some IDEA key conflict with the following MAC key shortcuts:

  • Spotlight search (command+space)
    Preferences ->Keyboard -> Shortcuts -> Spotlight. ( remat to option + space for example)
  • Hide window (command + space)
    Control + h ( shows hierarhy in IDEA)
  • Quit program (control + q)
    In IDEA it is showing

Summary

Using those steps I was able to achieve very similar keyboard shortcut mappings to Windows on the latest Mac OS X. It took me a good day to get the hang of all the differences. That said, I believe you in luck as have landed on this article with a similar problem. Now, it should consume no more than 15 minutes to apply all the described modifications. In case of questions or any caveats that you might want to add, please feel free to comment underneath or reach me in any other way.

References:

  1. https://stackoverflow.com/questions/35874608/intellij-default-windows-keymap-on-mac-os-x
  2. https://resources.jetbrains.com/storage/products/intellij-idea/docs/IntelliJIDEA_ReferenceCard.pdf
  3. https://gist.github.com/vikreinok/69e18a79d08db956db4b56a9ae2feb91

Software developer