Rebind Caps Lock key to Escape/Control

Introduction

For vim users, rebinding CAPS LOCK to the ESCAPE key makes it easier to switch modes. For Emacs users, it's helpful to rebind CAPS LOCK to the CTRL key. Here are instructions on how to map your CAPS LOCK key to either ESCAPE or CTRL for Windows, Mac, and Linux.

Mac

In Mac OSX, go to System Preferences | Keyboard | Keyboard | Modifier Keys and then change Caps Lock Key to Escape or Control option.

Windows

Install AutoHotkey and create a new AutoHotkey script by creating a new file named Caps2Esc.ahk or right clicking in a folder and choosing New -> AutoHotkey Script. Inside the script put the following:

Capslock::Esc

Double-click the file or run it directly from the command line to start the script in the background.

To run the script on startup, open the Startup directory by pressing Windows Key + r and running shell:startup. Place the AutoHotkey script in there.

KDE

In KDE, go to System Settings | Hardware | Input Devices | Advanced | Caps Lock behavior. From there you can choose either Make Caps an additional Esc or Caps Lock is also a Ctrl.

Gnome

GUI

In Gnome desktops this GUI options is available.

sudo apt install dconf-tools
dconf-editor

In dconf-editor, navigate to /org/gnome/desktop/input-sources/ and modify the xkb-options value with a settings value from below.

CLI

The command-line version is a reliable option as well for Gnome desktops.

Example:

# Get current settings first
dconf read /org/gnome/desktop/input-sources/xkb-options
# Update settings
dconf write /org/gnome/desktop/input-sources/xkb-options "['caps:escape']"

xkb-options

These are some of the options you can pass to xkb-options in the Gnome examples above.

  • ['caps:escape'] - Make Caps act like Esc
  • ['caps:ctrl_modifier'] - Make Caps act like Ctrl
  • ['ctrl:swapcaps'] - Swap Caps and Ctrl
  • ['caps:swapescape'] - Swaps Caps and Ctrl

Notes on VS Code

In Linux, I have had issues with the keybinding being recognized. To fix this, I modified my settings.json file to include the following setting:

"keyboard.dispatch": "keyCode",

Conclusion

You should now know how to rebind your CAPS LOCK key to either ESC or CTRL keys in Linux, Mac, and Windows environments.