24

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?

4 Answers 4

26

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.

6
  • 8
    In order to figure out that I wanted caps:escape as my XKBOPTIONS I needed to search through the many options in /usr/share/doc/keyboard-configuration/xorg.lst. Mar 9, 2013 at 17:59
  • 1
    @EricWilson Yea, the documentation is ... suboptimal.
    – Raphael
    Mar 9, 2013 at 18:02
  • 2
    On Raspbian jessie, at least, this only affects the text console, not the GUI. See this other answer for a solution that affects the GUI. Jan 14, 2017 at 21:37
  • For me, only this answer worked, and not the one from @LuísOliveira
    – Bogatyr
    Feb 26, 2017 at 18:29
  • 1
    @Bogatyr it depends on which terminal you are using. If you are working without X11 (graphical environment) this is the solution, if you are working on X11 the working solution is in the yzsh reply. They are two distinct environment so every one has his own configuration. Maybe the two answer should be put togheter explaining the context.
    – karlacio
    Jan 26, 2018 at 17:08
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.

3
  • Thanks! This one work for me on jessie. Editing esc/default/keyboard did not. Your example swaps ctrl and caps. To answer the question directly, to map caps to esc use the 'option = caps:escape".
    – FeFiFoFu
    Nov 5, 2016 at 17:41
  • 1
    That last tip should read ctrl:nocaps rather than ctrl:nocap. Other than that, it worked for me, thanks! Jan 14, 2017 at 21:41
  • Didn't work for me, but the accepted answer did.
    – Bogatyr
    Feb 26, 2017 at 18:29
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.

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'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.