Having to press the
esc key every time that you want to enter normal mode is a pain.
I have seen multiple answers where people map combinations like
jj. But why use that when you can map the
Having to press the
Edit: my first answer missed the question title, sorry.
why vi-map instead of system keys-swap?
Many people can have access to a Vi-like editor but not to system settings. Think of your university or enterprise account, or any online account in a box that's not your own computer. In those cases you cannot map a key to another because you don't have administrator privileges.
However some systems may let you do it on user's level: I think it's the case with Mac OS X and also GNU/Linux distros if allowed by root.
Some operating systems may be a pain to switch such keys even when you have full admin rights (hi Windows)
Well, when people can swap two special keys of their keyboards, they may choose to no do it ...because they have some other needs than Vi or Vim. For example, with standard keyboards, I also like to have Escape at CapsLock location when using the editor, but I prefer to have Control at the same location for other usage in the shell.
When the need is for a program only and not all stuffs, it's very nice and handy to have the feature inside. Plus, your Vi' setting can easily follow you from an account to another (here we loop with the first part of my answer) ...and it's easier to give a answer that is contained with the program instead of having to deal with all OS related nightmares. (last, we're on vi.SE here and not on: SU/U&L.SE/askubuntu/etc. haha)
how keys-swap on GNU/Linux per user?
They're many answers on how to do it, and the OP found some of them. But it's system wide and not all users want that... Like on Mac OS X, it may be a user preference easily configured via the Desktop Environment interface:
- with GNOME3, you'll need the Tweaks app installed (that's how the administrators allow the users to customise that parts of their desktop with ease, and the package is often named
gnome-tweak-tool). From that point
- Start the Tweaks application.
- Select "Keyboard & Mouse" from the left-hand menu.
- Click "Additional Layout Options".
- Click "Ctrl position" or "Caps Lock behaviour" on the window that opens and choose yours.
- with KDE Plasma, that part is available by default.
- Start the System Settings app.
- Go to "Input Devices" panel.
- Click "Keyboard" category.
- Click "Advanced" tab.
- Click "Ctrl position" or "Caps Lock behavior" then choose yours.
- to found and complete for LXQt and LXDE
- the Xfce desktop environment doesn't have a handy tool for managing these kinds of settings, we'll have to go console by way by running (put it in your
/usr/bin/setxkbmap -option "$flag"
$flagis one of (not exhaustive)
ctrl:nocaps— ⇪ as ⎈.
caps:none– Disables ⇪.
caps:super– ⇪ becomes an additional ❖ or ⌘ or ⊞.
caps:ctrl_modifier– ⇪ becomes an additional ⎈.
caps:numlock– ⇪ becomes an additional ⇭.
caps:escape– ⇪ becomes an additional ⎋.
caps:backspace– ⇪ becomes an additional ⌫.
caps:swapescape– ⇪ becomes ⎋, and ⎋ becomes ⇪.
- note that, in previous descriptions, I try to use ISO/IEC 9995 labels.
- still in console, one may use XModMap (commands like
xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape'or use of
~/.xmodmapfile) As it's deprecated in favour of SetXKbMap, I won't elaborate anymore.
I 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.
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
- 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
Identifier "keyboard defaults"
Option "XKbOptions" "caps:escape"
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
In order to use it you will need to press the
- Script and location of the file https://wiki.archlinux.org/title/X_keyboard_extension
- Being able to still use the
- Being able to edit a readonly permission file https://unix.stackexchange.com/questions/71109/how-can-i-exit-from-read-only-mode-in-vim