27

I'm used to mapping Caps Lock to Escape, particularly for use in Vim.

In Ubuntu, this is simple from the GUI. In other distros, a utility like xmodmap can be used. I tried this, but it seems that xmodmap cannot be installed by apt.

Can this sort of remapping be easily accomplished on the RPi?

Eric Wilson
  • 1,745
  • 5
  • 16
  • 14

5 Answers5

29

On Raspbian, edit the file /etc/default/keyboard and then run sudo dpkg-reconfigure keyboard-configuration. You may have to restart your terminal and/or the Pi for everything to take effect.

The particulars of what you need to enter depend on what you want to do. For me, this:

XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT="altgr-intl"
XKBOPTIONS="terminate:ctrl_alt_bksp,ctrl:nocaps"

makes sure I have US international keyboard layout and Caps Lock acts as Control (that's the ctrl:nocaps part).

Find out more via man keyboard.

Raphael
  • 576
  • 1
  • 6
  • 16
9

In my case, Raspbian (jessie):

$ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
...

$ sudo vi ~/.config/lxkeymap.cfg
option = ctrl:swapcaps

or

option = <something>,ctrl:swapcaps

then

$ sudo reboot

ctrl:swapcaps swaps the Ctrl and CapsLock keys. If you'd like to just replace CapsLock and keep the original Ctrl as is, use ctrl:nocaps instead.

Luís Oliveira
  • 103
  • 1
  • 3
yzsh
  • 91
  • 1
  • 2
3

tl;dr: it can be added through the GUI, in the Keyboard Layout Handler applet's settings.

Add the Keyboard Layout Handler applet to your panel:

Right click on panel > Panel Settings > Panel Applets tab > Click Add > Scroll and select Keyboard Layout Handler and click Add.

enter image description here

Open Keyboard Layout Handler applet's settings:

Right click on the newly added applet > Keyboard Layout Handler Settings.

enter image description here

Set xkbmap options

Then on the right find Advanced setxkbmap Options, and input caps:escape (or ctrl:nocaps, etc, here's a list). Multiple options probably need to be comma separated.

enter image description here

There's a green icon on the right of the box, I suppose one should click on it to save the settings, though there's no feedback to confirm. I can't remember if I needed to reboot for the changed to take effect.

mynyml
  • 131
  • 3
2

In October 2024, Raspberry Pi switched to the labwc compositor 1, and it uses XKB_DEFAULT_OPTIONS in ~/.config/labwc/environment. So, to turn your caps lock key into a control, you could put this line into that file:

XKB_DEFAULT_OPTIONS=ctrl:nocaps

I haven't tried the rest of the options in /usr/share/X11/xkb/rules/base.lst, but that's where I'd look for other remappins.

2

xmodmap can indeed be installed on the RPi using apt:

apt-get install x11-xserver-utils

To make your Caps Lock key act as Esc, you could then run

xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape'
Dmitry Grigoryev
  • 28,277
  • 6
  • 54
  • 147