parallax
Jason Martin

Tech Evangelist & Software Engineer

MacOS & Windows muscle memory keybindings
Productivity
Tools
MacOS

Power at your fingertips

  • When switching between MacOS and Windows, the keyboard position for shortcuts such as copy and paste are switched from Ctrl to Cmd
    • Since these are in different places on the keyboard, user needs to press a different key on the keyboard, which interferes with muscle memory
  • Simply swapping Ctrl and Cmd via the Keyboard preferences isn’t a straightforward solution, because then using muscle memory for Ctrl codes in terminal and VIM are now displaced
  • Another alternative instead of swapping Ctrl and Cmd would be to rebind every single possible command, such as Cmd + C, V, H, Q, T (and so forth) to use Ctrl instead (via Keyboard preferences)
    • This solution is overly cumbersome and every single possible combination would have to be considered one-by-one
  • This conundrum also applies to using the Caps lock as a modifier key when pressed with other keys, and escape when pressed by itself
    • On windows, I use Caps to rebind to the Ctrl modifier when pressed with another key
    • This allows for Caps + C / V to copy and paste respectively
    • However, if in MacOS Caps is rebinded to Cmd (via Karabiner elements), then it will work for copy and paste, but then none of the Ctrl modifiers for Vim such as Ctrl + U (undo) or Ctrl + C (break) will work in terminal.
  • The best solution I’ve found so far, is NOT swapping Ctrl and Cmd****, but altering the behavior of the Caps modifier so that it sends Ctrl keycodes in Terminal based apps such as iTerm and VS Code, otherwise by default send Cmd****.
    • This is done by setting the logic based on the active foreground app: if the foreground app is a terminal based app, then activate the CapsCtrl modifier rule, otherwise activate the CapsCmd rule by default.

My Karabiner JSON config

  • To add or remove apps, modify bundle_identifiers
  • Can find bundle_identifier by: osascript -e 'id of app "Name of App"'
  • Can use Karabiner Complex Modification tool, or edit JSON file directly (examples below used the modification tool)
{
  "title": "Change caps_lock to command",
  "rules": [
    {
      "description": "Change caps_lock to Command if pressed with other keys, to escape if pressed alone.",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "caps_lock",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "left_command"
            }
          ],
          "to_if_alone": [
            {
              "key_code": "escape"
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "^com\\.microsoft\\.VSCode",
                "^com\\.googlecode\\.iterm2"
              ]
            }
          ]
        }
      ]
    }
  ]
}
{
  "title": "Change caps_lock to CTRL",
  "rules": [
    {
      "description": "Change caps_lock to CTRL if pressed with other keys, to escape if pressed alone. (APP SPECIFIC)",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "caps_lock",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "left_control"
            }
          ],
          "to_if_alone": [
            {
              "key_code": "escape"
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "com\\.microsoft\\.VSCode",
                "com\\.googlecode\\.iterm2"
              ]
            }
          ]
        }
      ]
    }
  ]
}