Skip to content

Instantly share code, notes, and snippets.

@croian
Last active December 17, 2023 19:26
Show Gist options
  • Save croian/3cd8651e04e8d494235474992c0d0486 to your computer and use it in GitHub Desktop.
Save croian/3cd8651e04e8d494235474992c0d0486 to your computer and use it in GitHub Desktop.
A Complete (but condensed) Guide to Customizing Mac Keyboard Shortcuts

A Complete (but condensed) Guide to Customizing Mac Keyboard Shortcuts

To help make Mac keyboard shortcuts more like Windows/Linux, and/or just customize them to your liking and boost your productivity.

The instructions here worked for me on macOS Ventura 13.4.1 (22F82) and with Karabiner-Elements (where applicable) version 14.12.0.

This is the condensed version of the guide, meant for advanced users or as reference. For more complete explanation and explicit instructions see the standard version.

Swapping command and control keys

  1. Open the System Settings app
  2. Go to Keyboard -> Keyboard Shortcuts... -> Modifier Keys
  3. Select the desired keyboard from the dropdown menu
  4. Map the Control (^) Key to ⌘ Command
  5. Map the Command (⌘) Key to ^ Control

Shortcuts configurable in Settings app

Some macOS shortcuts are configurable in the System Settings app.

  1. Open the System Settings app
  2. Go to Keyboard -> Keyboard Shortcuts...

Where you can remap e.g. Mission Control's Move left/right a space shortcuts to be like Windows' win+left/right shortcuts for desktop switching. Double-click a shortcut to edit it.

Shortcuts configurable via DefaultKeyBinding.dict

Some macOS shortcuts -- those that deal with navigating, selecting or manipulating text -- are configurable via adding/editing an XML property list file at ~/Library/KeyBindings/DefaultKeyBinding.dict. Be sure to restart your apps after editing/saving this file, for the changes to take effect.

NOTE: Some apps have their own full or partial overrides of these shortcuts, so these remaps may not work everywhere (see Karabiner Complex Modifications for a solution). E.g. Webstorm has its own customizable shortcuts for these actions, and Slack will honor moveWord[Left/Right] remaps but not moveTo[Beginning/End]OfLine remaps.

Here is my full file as of now, to make text navigation and manipulation more like Windows/Linux:

{
  "@\UF702"  = moveWordLeft:;                                // cmd-left
  "@\UF703"  = moveWordRight:;                               // cmd-right
  "@$\UF702" = moveWordLeftAndModifySelection:;              // cmd-shift-left
  "@$\UF703" = moveWordRightAndModifySelection:;             // cmd-shift-right
  "\UF729"   = moveToBeginningOfLine:;                       // home
  "\UF72B"   = moveToEndOfLine:;                             // end
  "$\UF729"  = moveToBeginningOfLineAndModifySelection:;     // shift-home
  "$\UF72B"  = moveToEndOfLineAndModifySelection:;           // shift-end
  "@\UF729"  = moveToBeginningOfDocument:;                   // cmd-home
  "@\UF72B"  = moveToEndOfDocument:;                         // cmd-end
  "$@\UF729" = moveToBeginningOfDocumentAndModifySelection:; // cmd-shift-home
  "$@\UF72B" = moveToEndOfDocumentAndModifySelection:;       // cmd-shift-end
  "@\U007F"  = deleteWordBackward:;                          // cmd-backspace
  "@\UF728"  = deleteWordForward:;                           // cmd-delete
}

There's a lot more you can do with this file/method. See these resources for more info:

Disabling alt+[letter] foreign/special characters

Doing this will free up your alt key for shortcuts:

  1. Open System Settings app
  2. Go to Keyboard
  3. Under the Text Input section, in the Input Sources subsection click the Edit... button
  4. Turn on Show Input menu in menu bar
  5. If Unicode Hex Input is not listed in the input sources on the left:
    1. Click the + in the lower left of the dialog
    2. In the language selection on the left, scroll all the way down and select Others
    3. In the list on the right select Unicode Hex Input
    4. Click the Add button
  6. In the system menu bar (upper-right), click the Input menu (probably says US) and select Unicode Hex Input

Simple key (or mouse button) remaps

Use Karabiner-Element's Simple Modifications feature for simple single-key/button to single key/button remaps. It's pretty self-explanatory when you see it.

E.g. if my keyboard doesn't have mouse capability in its firmware, I'll map keypad_enter to a key (in a firmware or layout editor, like https://usevia.app), then use Karabiner to map keypad_enter to button1 (left mouse button).

Complex and per-app remaps

Karabiner's Complex Modifications feature can give you even more capabilities.

To edit the rules, you can create/modify the ~/.config/karabiner/karabiner.json file directly, or you can try the steps below for a more gui-oriented process.

Note on mice / pointer devices: To map mouse buttons to actions, you may have to go the the "Devices" section of Karabiner settings, and enable the "Modify events" option for your mouse. I found that my logitech mouse had two entries in "Devices" -- one as a keyboard (for some reason) and one as a mouse, and it seems "Modify events" was off by default for the mouse entry.

NOTE: This app and the methods I've found for configuring remaps are quite strange and non-user-friendly. But if you carefully follow these steps and the tips here, you should have success.

Example

Because Slack does not honor moveToEndOfLine remaps, let's rectify that by doing the following:

  1. Open Karabiner-Elements app
  2. Copy the following to clipboard:
{
  "title": "Ian's rules",
  "rules": [
    {
      "description": "Slack Home/End",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "home",
            "modifiers": { "optional": ["left_shift"] }
          },
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": ["com.tinyspeck.slackmacgap"]
            }
          ],
          "to": [{
            "key_code": "left_arrow",
            "modifiers": ["left_command"]
          }]
        },
        {
          "type": "basic",
          "from": { 
            "key_code": "end",
            "modifiers": { "optional": ["left_shift"] }
          },
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "com.tinyspeck.slackmacgap"
              ]
            }
          ],
          "to": [{
            "key_code": "right_arrow",
            "modifiers": ["left_command"]
          }]
        }
      ]
    }
  ]
}
  1. In your web browser, go to https://genesy.github.io/karabiner-complex-rules-generator/
  2. Paste the JSON into the lower text box on the right side of the webpage
  3. Click outside the text box (this will trigger the JSON to load)
  4. Click the Install! button -- this should open a dialog in the Karabiner app
  5. Click the Import button
  6. Click Enable next to the Slack Home/End rule, or click Enable All in the lower right of the Ian's rules section
  7. Home/End should go to the beginning/end of line in Slack now, and shift+Home/End should select to the beginning/end of line. Voilà!

Use Karabiner's EventViewer (accessible by clicking its menu bar status icon) to find key codes, bundle identifiers, and app file paths.

More resources on Karabiner

Direct app switching

This is not a remap of a native feature, but it's something I find so incredibly useful (especially on a small, single monitor) on both Windows (via AutoHotkey) and Mac, that I'll put it here.

To assign cmd+ctrl+s to Slack, import the following JSON into Karabiner:

{
  "title": "Ian's rules",
  "rules": [
    {
      "description": "App switcher/launchers",
      "manipulators": [
        {
          "type": "basic",
          "from": { "key_code": "s", "modifiers": { "mandatory": ["left_control", "left_command"] } },
          "to": [{ "shell_command": "open '/Applications/Slack.app'" } ]
        }
      ]
    }
  ]
}

...add a "manipulator" entry for each app you commonly use, and your productivity will instantly increase.

Miscellanea

  • ctrl+F2 is the default shortcut for moving focus to the system menu bar, but it doesn't seem to work for me on macOS 14.1.1 -- going to System settings > Keyboard > Keyoboard Shortcuts > Keyboard and swapping it with Move focus to the Dock (ctrl+F3) seems to allow both to work.

One last thing

Karabiner's complex modifications can be used to add layers to your keyboard, so you don't need to stray far from the home row for e.g. arrows keys and everything else.

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