2

My goal is to PERMANENTLY remap CAPSLOCK into ESC key under Ubuntu 22.04.3 with Wayland display server.

Second requirement is to do it without installing additional software.

I need it for VIM, to be fast and effective using text editor.

I've tried few ways to do it, but since I'm not experienced Linux user, I've failed.
First thing I've tried was in this article.
It's written there to execute the following command: setxkbmap -option caps:escape in order to remap CAPSLOCK into ESC and it even works temporarily.

I check the results here.
But as stated in the article, the mapping is only temporary.

Therefore I'm heading forward to make it PERMANENT, by editing the /etc/default/keyboard file. Like so:

# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) manual page.

XKBMODEL="pc105" XKBLAYOUT="us" XKBVARIANT="" XKBOPTIONS="caps:escape" BACKSPACE="guess"

https://thesynack.com/posts/persistent-capslock-behavior/

https://askubuntu.com/questions/363346/how-to-permanently-switch-caps-lock-and-esc

But it still won't work after the Ubuntu restart and I don't understand why?

Is this article I'm using to remap CAPSLOCK into ESC X11 specific?

Because I'm using Wayland display server. It's default in my Ubuntu Ubuntu 22.04.3.

I've also read carefully this question over here and all the answers provided. Although there's a lot of knowledge and accepted answers, the whole thread is 10 years old - long before Wayland was the default display server in Ubuntu - therefore I've felt at liberty to ask this question again.

michal roesler
  • 219
  • 1
  • 11

1 Answers1

1

After 2 days of using computer and 4 or 5 power on/off cycles, the CAPSLOCK started to work as an ESC key as I initially wanted.

I haven't done anything more than described in the question. And I have no idea, why this /etc/default/keyboard file edit, didn't take effect after first computer restart. But I'm happy it finally started working as described here.

There's also another file you might want to check, but not edit.
It's /usr/share/X11/xkb/rules/base.lst file.
You can find all options regarding how the CAPSLOCK behavior can changed. This is the short list of the possibilities:

  ctrl:nocaps          Caps Lock as Ctrl
  ctrl:swapcaps        Swap Ctrl and Caps Lock
  ctrl:swapcaps_hyper  Caps Lock as Control, Control as Hyper

caps:swapescape Swap ESC and Caps Lock caps:escape Make Caps Lock an additional Esc caps:escape_shifted_capslock Make unmodified Caps Lock an additional Esc, but Shift + Caps Lock behaves like regular Caps Lock caps:super Make Caps Lock an additional Super caps:ctrl_modifier Caps Lock is also a Ctrl

If you want to grep the /usr/share/X11/xkb/rules/base.lst file on your own, try this command:

grep "caps" /usr/share/X11/xkb/rules/base.lst

My final /etc/default/keyboard file contents, that PERMANENTLY remapped CAPSLOCK into ESC key under Ubuntu 22.04.3 is as follows:

# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) manual page.

XKBMODEL="pc105" XKBLAYOUT="us" XKBVARIANT="" XKBOPTIONS="caps:escape" BACKSPACE="guess"

https://thesynack.com/posts/persistent-capslock-behavior/

https://askubuntu.com/questions/363346/how-to-permanently-switch-caps-lock-and-esc

But as I've said in the beginning, it only started to work after 2 days and 4 or 5 power on/off cycles - I don't know why it didn't work from the start.

Also this thread was extremely helpful and provided a lot of info regarding how remapping keys under Linux works.

ADDITIONALLY I've found that paragraph in the same thread I've recommended above.

In Debian systems, changes in /etc/default/keyboard do not become immediately visible to X. You should either reboot the system, or use sudo udevadm trigger --subsystem-match=input --action=change.
https://linux.die.net/man/8/udevadm

In order to activate the changes on the console, run setupcon(1).

michal roesler
  • 219
  • 1
  • 11