Skip to content

Instantly share code, notes, and snippets.

@ianchen06
Forked from tanyuan/smart-caps-lock.md
Created June 19, 2018 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianchen06/3c0ff6dbfb2ec539577fffc58a71e4a7 to your computer and use it in GitHub Desktop.
Save ianchen06/3c0ff6dbfb2ec539577fffc58a71e4a7 to your computer and use it in GitHub Desktop.
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.

Happy Vimmimg!

Mac (macOS Sierra not supported)

Step 1. Remap Caps Lock to Control

Open System Preferences, then go into the Keyboard preference pane, click Modifier Keys…, and change Caps Lock Key to Control.

Step 2. Install Karabiner

Download and install Karabiner. (A powerful and stable keyboard customizer for OS X)

In Change Key pane, find Change Control_L Key (Left Control). Then toggle on the following:

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

And the effect should apply immediately.

Happy Vimmimg!

Windows

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

Happy Vimmimg!

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