Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Smart Caps Lock: Remap Caps Lock to Control AND Escape

Smart Caps Lock: Remap to Control AND Escape (Linux, Mac, Windows)

Caps Lock 變成智慧的 Control 以及 Escape

  • 單獨輕按一下就是 Escape
  • 若按下時同時按著其他鍵,就會是 Control

這應該是 Vim 和 Emacs 的最佳解了!(Emacs? Bash 的快捷鍵就是 Emacs 系列的)

  • Send Escape if you tap Caps Lock alone.
  • Send Control if you press Caps Lock with another key.

For both Vim and Emacs world.

GNU/Linux

Step 1. Install XCAPE

Install XCAPE (xcape). (Linux utility to configure modifier keys to act as other keys when pressed and released on their own.)

Ubuntu:

sudo apt-get install xcape

Step 2. Run the command

# make CapsLock behave like Ctrl:
setxkbmap -option ctrl:nocaps

# make short-pressed Ctrl behave like Escape:
xcape -e 'Control_L=Escape'

The effect should apply immediately.

Step 3. Autostart

Append code from Step 2 to file ~/.xprofile to run the command when X starts.

macOS

  1. Download and install Karabiner-Elements, a powerful and stable keyboard customizer.
  2. Open Karabiner-Elements, select Complex Modifications tab, and click Add rule at the bottom.
  3. Find Post escape if caps is pressed alone, left_ctrl otherwise and click on enable.

The effect should apply immediately.

Windows

Option 1:

  1. Download and install AutoHotKey.
  2. Use the script CapsLockCtrlEscape.ahk.

Option 2:

Download and run dual-key-remap. (Note that in config.txt, CONTROL might needed to changed to LEFT_CTRL for some computers)

For both options, the effect should apply immediately.

@gustavetd

This comment has been minimized.

Copy link

gustavetd commented Apr 10, 2018

Thanks!

@jtaxen

This comment has been minimized.

Copy link

jtaxen commented Aug 31, 2018

This was very handy!

@sandangel

This comment has been minimized.

Copy link

sandangel commented Sep 20, 2018

could you please help with config Control_L + hjkl to arrow key on both linux and macOS?

@Abraxas-Knister

This comment has been minimized.

Copy link

Abraxas-Knister commented Jun 23, 2019

I did this, I got "WARNING: No keycode found for keysym Escape (0xff1b) in mapping Control_L. Ignoring this mapping."

@Abraxas-Knister

This comment has been minimized.

Copy link

Abraxas-Knister commented Jun 23, 2019

Surrendered, turns out I should have run an "setxkbmap -option" (notice empty argument) first.

@likern

This comment has been minimized.

Copy link

likern commented Jul 6, 2019

Does anyone know how to do that purely with XKB?

@yahkun

This comment has been minimized.

Copy link

yahkun commented Jul 24, 2019

Thanks, this is very helpful~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.