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).