Science and technology

Remap your Caps Lock key on Linux

There have been many life-changing Linux moments for me, however most fade into my backstory as they turn into the established order. There’s one little keyboard trick Linux taught me that I am reminded of each time I exploit it (possibly 1,000 instances a day), and that is changing the Caps Lock key to Ctrl.

I by no means use Caps Lock, however I exploit the Ctrl key all day for copying, pasting, navigating inside Emacs, and invoking Bash, GNU Screen, or tmux actions. Caps Lock occupies invaluable actual property on my keyboard, forcing the really helpful Ctrl key right down to the awkward-to-reach backside nook.

Remapping Ctrl elevated my typing and navigation velocity and has in all probability saved me from repetitive stress accidents.

The case of the disappearing management

Buckle in, this can be a curler coaster of a historical past lesson:

Unfortunately for Caps Lock swappers like me, when GNOME three got here out, all of it however eliminated the power to alter the situation of the Ctrl key.

Fortunately, the superb GNOME Tweaks app introduced again these “missing” management panels.

Unfortunately, GNOME 40 has no GNOME Tweaks app (but?)

Also, sadly, the outdated xmodmap hack that used to work on X11 is ineffective on the brand new Wayland display server.

For a short time (a day at greatest), I felt issues had been wanting dim for individuals who hate Caps Lock. Then I remembered I’m a consumer of open supply, and there is all the time a approach round one thing so simple as an missed GUI management panel.

dconf

The GNOME desktop makes use of dconf, a database that shops essential configuration choices. It’s the backend to GSettings, which is the system GNOME functions interface with when they should uncover system preferences. You can question the dconf database utilizing the gsetting command, and you’ll set dconf key values instantly with the dconf command.

GSettings

The dconf database is not essentially what you would possibly name discoverable. It’s a humble database you are not meant to have to consider, and it holds a number of information you often do not must work together with instantly. However, it does use a smart schema that is enjoyable to browse if you wish to higher perceive all the desire choices GNOME has to handle.

You can record all of dconf’s schemas with the list-schemas subcommand. After searching lots of of schemas, you would possibly use grep to slender your focus to one thing that appears particularly related, resembling org.gnome.desktop:

$ gsettings list-schemas | grep ^org.gnome.desktop
[...]
org.gnome.desktop.background
org.gnome.desktop.privateness
org.gnome.desktop.remote-desktop.vnc
org.gnome.desktop.interface
org.gnome.desktop.default-applications.terminal
org.gnome.desktop.session
org.gnome.desktop.thumbnailers
org.gnome.desktop.app-folders
org.gnome.desktop.notifications
org.gnome.desktop.sound
org.gnome.desktop.lockdown
org.gnome.desktop.default-applications.workplace

Whether via a handbook search or via reading GSetting documentation, you might discover the org.gnome.desktop.input-sources schema, which helps outline the keyboard structure. A GSetting schema, by design, comprises keys and values.

Remapping Caps Lock with dconf

The xkb-options key comprises optionally available keyboard overrides. To set this key, use dconf, changing the dots (.) within the schema above to slashes (/) as a result of the dconf database requires it:

$ dconf write /org/gnome/desktop/input-sources/xkb-options "['caps:ctrl_modifier']"

I set caps to ctrl_modifier as a result of I exploit the Ctrl modifier greater than some other modifier, however Vim customers might choose to set it to escape as an alternative.

View your setting

The change takes impact instantly and persists throughout reboots. It’s a desire you’ve got outlined in GNOME, so it stays in impact till you alter it.

You can view the brand new worth in dconf with gsettings. First, view the obtainable keys:

$ gsettings list-keys
org.gnome.desktop.input-sources
xkb-options
mru-sources
show-all-sources
present
per-window
sources

And then view the settings with the xkb-options key:

$ gsettings get
org.gnome.desktop.input-sources
xkb-options
['caps:ctrl_modifier']

Options aplenty

I exploit this little trick to set Caps Lock in addition to the Compose key (compose:ralt) on my GNOME three.four system. While I consider there are GUI controls in improvement to manage choices like these, I additionally must admit that the power to set them programmatically is a luxurious I take pleasure in. As a former admin of techniques that had no dependable method to alter desktop settings, the power to script my preferences makes establishing a contemporary desktop fast and simple.

There are numerous helpful choices obtainable with GSettings, and the documentation is thorough. If you could have one thing you wish to change, check out what’s obtainable.

Most Popular

To Top