sajad torkamani

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 \
        checkinstall

Install xcape

TEMP_DIR=/tmp/xcape && mkdir $TEMP_DIR
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 if setxkbmap command is not recognized.

Tagged: Ubuntu

Leave a comment

Your email address will not be published. Required fields are marked *