Remap Caps Lock to Ctrl and Esc on Ubuntu
11 March 2022 (Updated 11 March 2022)
We want to change the behaviour of CapsLock
so that when pressed on its own, it acts as Esc
, and when pressed with another key, it acts as the Ctrl
modifier. This mapping is handy for Vim.
Install dev dependencies
sudo apt install -y gcc \
make \
pkg-config \
libx11-dev \
libxtst-dev \
libxi-dev
Install xcape
TEMP_DIR=/tmp/xcape
git clone https://github.com/alols/xcape.git $TEMP_DIR
cd $TEMP_DIR && make
sudo checkinstall -y
sudo rm -rf $TEMP_DIR
Verify xcape
installation
which xcape
You should see the path to its executable (e.g., /usr/bin/xcape
).
Set up the binding of CapsLock to Ctrl and Esc
Add the following lines to your shell start up file (e.g., .zshrc
, .bashrc
).
# Remap caps lock to act as Escape when short-pressed
# and as Ctrl when long-pressed.
setxkbmap -option ctrl:nocaps
xcape -e 'Control_L=Escape'
Troubleshoot
- Install
x11-xkb-utils
ifsetxkbmap
command is not recognized.
Tagged:
Ubuntu