15

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?

20

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
    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. – Eric Wilson Mar 9 '13 at 17:59
  • 1
    @EricWilson Yea, the documentation is ... suboptimal. – Raphael Mar 9 '13 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. – Luís Oliveira Jan 14 '17 at 21:37
  • For me, only this answer worked, and not the one from @LuísOliveira – Bogatyr Feb 26 '17 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 '18 at 17:08
8

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.

  • 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 '16 at 17:41
  • 1
    That last tip should read ctrl:nocaps rather than ctrl:nocap. Other than that, it worked for me, thanks! – Luís Oliveira Jan 14 '17 at 21:41
  • Didn't work for me, but the accepted answer did. – Bogatyr Feb 26 '17 at 18:29
1

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, privacy policy and cookie policy

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