Question

I generally run Linux. I use Vim a lot, so the Escape key is extremely important. I also use other keyboard shortcuts a lot, so Control is "key" as well. On Linux, I've solved this by using xcape to map the Caps lock key to Escape if pressed by itself, or Control if pressed in combination with another key. This puts the best of both worlds within quick reach of my pinky finger. Is there any way I can do this on a Mac?

Was it helpful?

Solution

Yes, using Karabiner (formerly KeyRemap4Macbook).

First, go into the Keyboard preference pane, click "Modifier Keys…", and change Caps Lock to Control. Then, go into Karabiner and search for this option:

Control_L to Control_L
      (+ when you type Control_L only, send Escape)

Check that, and you're done. With Karabiner you can do lots more interesting things, like mapping your (now kind of useless) Escape key to a Hyper key with even more keybindings.

OTHER TIPS

Karabiner is currently incompatible with MacOS Sierra. Another, Sierra-friendly solution, is with Keyboard Maestro (it is not free). Change the behavior of the Caps-Lock key to Control through System Preferences -> Keyboard -> Modifier Keys as others have suggested.

Then within Keyboard Maestro, setup a macro as follows:

  • Triggered by USB Device Key Trigger
  • Press the Caps-Lock key on your keyboard
  • is tapped once
  • with these modifiers: ^
  • (you will need to repeat the previous trigger for each USB keyboard you use)
  • Then add an action Text -> Type a keystroke
  • Press Esc

To do it with Karabiner Elements, which supports macOS 10.12 and later, open ~/.config/karabiner/karabiner.json, and add the following rule to the rules array.

{
  manipulators: [
    {
      description:
        "Change caps_lock to control when used as modifier, escape when used alone",
      from: {
        key_code: "caps_lock",
        modifiers: {
          optional: ["any"]
        }
      },
      to: [
        {
          key_code: "left_control"
        }
      ],
      to_if_alone: [
        {
          key_code: "escape",
          modifiers: {
            optional: ["any"]
          }
        }
      ],
      type: "basic"
    }
  ]
}

You can also try to use ControlEscape.spoon with Hammerspoon.

Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top