inI did find the answer but it was split up between sites and I thought that it would be a good idea to unite them in a question aaaaaaaaaaaaaaaaaaa.
Truth is that you can't do this natively in vim, but you need to implement it system-wide. As the capslock
key doesn't mean anything on it's own.
How to do this:
- Go to this directory
/etc/X11/xorg.conf.d/
- There you will find a text file named like something like
90-custom-kbd.conf
(this may vary, in my case it was preceded by a 00 instead of a 90) - Enter the file with vim and write the following
#keybind capslock as esc
Section "InputClass"
Identifier "keyboard defaults"
MatchIsKeyboard "on"
Option "XKbOptions" "caps:escape"
EndSection
6.in order to save it you need to enter vim normal mode and write
:w !sudo tee %
- w writes the buffer,
- !sudo calls the shell with sudo,
- tee redirects the output of vim :w to the output with tee, and
- % is the current filename
Enter the sudo password and press L
- Reboot the computer
if you still wish to use the capslock
key you can by in the line before the EndSection
where it says caps:escape
type caps:escape_shifted_capslock
In order to use it you will need to press the shift
key
Sources:
- Script and location of the file https://wiki.archlinux.org/title/X_keyboard_extension
- Being able to still use the
capslock
key https://www.reddit.com/r/vim/comments/k5twce/switching_esc_with_caps_lock/ - Being able to edit a readonly permission file https://unix.stackexchange.com/questions/71109/how-can-i-exit-from-read-only-mode-in-vim