Note: For Vim users, it is appealing to make the Caps Lock
function like Escape
.
It is suggested that you make Caps Lock
an additonal Escape
rather than swap them.
This avoid inconsistent key mapping issues when you work remotely via VNC, NoMachine, etc.
Desktop Environment
Some desktop environment (e.g., Cinnamon, GNOME, etc.) let you define behavior of keys.
GNOME
-
Install
gnome-tweaks
. You can use the following command on Debian/Ubuntu based Linux distributions.wajig install gnome-tweaks
-
Start gnome-tweaks by running the following command.
gnome-tweaks
-
Click on the "Keyboard & Mouse" button in the left panel and then the "Additional Layout Options" button under the Keyboard section.
-
In the prompt dialog, click on the triangle button next to "Caps Lock behavior" and then select the behavior you want for Caps Lock.
-
Restart your Linux machine.
Cinnamon
-
Open System Settings.
-
Select Keybord.
-
Keybord layouts
-
Options (on the right-bottom corner)
-
Caps Lock key behavior
-
Choose the behavior you want.
Keyboard Configuration
Keyboard is configured by the file /etc/default/keyboard
on Linux.
For example,
you can find the line that starts with XKBOPTIONS
,
and add ctrl:nocaps
to make Caps Lock an additional Control key
or ctrl:swapcaps
to swap Caps Lock and Control.
Run the following command after updating the file /etc/default/keyboard
to make it in effect.
sudo dpkg-reconfigure keyboard-configuration
This is the recommended way if you want to make key swaping persistent.
Another advantage it has over GUI configuration and setxkbmap
(see the next section)
is that the key swaping works in TTY (without X11 or Wayland).
setxkbmap
Swap the Caps and the Escape keys.
setxkbmap -option -option caps:swapescape
Unfortunately, the key mapping partially pass to virtual machines or remote desktops, which is the worst scenario. It is suggested that you turn off the mapping on the Linux host when you work in a VM or a remote desktop.