The compose key on Linux lets you input characters with accents or diacritics without changing keyboard layouts. You type something like Compose’e and get é. It’s very useful if you use English almost exclusively, but occasionally need to write in a language with extra letters. Let’s see how to enable the compose key, how to check what key combos are available by default, and how to add our own.
💭 The point of this post is to raise awareness that this exists. I didn’t know about it until last year, and I struggled with other ways of inputting special letters.
Before we can use compose, we have to bind it to a real key. In KDE and Gnome, we do this in the System Settings or Tweaks apps. In other desktop environments, we use something like
setxkbmap -option compose:menu or
xmodmap -e "keysym Menu = Multi_key". For instance, I have compose bound to the
Menu key because I can easily hit it with the side of my right hand.
The system powering this feature is called
XCompose, but despite its name, it works not only on X11, but also on Wayland.
Once enabled, we immediately have access to some five thousand key combos:
|Compose;t||ț||Romanian special letters|
⚠ GTK apps have a less flexible compose system by default. They use SCIM as their input method, which hard-codes a list of thousands of key combos in
scim_compose_key_data.h. The list is good enough for most use cases, but it’s not configurable like the XIM input method which we’ll be discussing below. We can make GTK apps use XIM with an environment variable.
The big advantage of XIM is that it’s configurable, but we also get some more interesting combos by default:
|Composepoo||💩||Best character of the iconic 2017 movie|
|ComposeFU||🖕||A measured response to Internet criticism|
|ComposeLLAP||🖖||Display your nerd creds|
|ComposeCCCP||☭||For when workers are oppressed|
Provided we’re using XIM, we can extend the default list of five thousand key combos with an
include "%L" # include defaults <Multi_key> <r> <t> : "ț" # extra letter <Multi_key> <d> <d> : "…" # more punctuation <Multi_key> <e> <s> : "😃" # emoji <Multi_key> <t> <y> : "Thank you!" # expand abbreviation <Multi_key> <p> <w> <d> : "hunter2" # enter your password
(unlike other X configuration files, the first two letters are in uppercase)
The syntax is described in
XCompose(3), but it’s quite limited. The
RESULT part of each rule has to be a Unicode string without any modifiers or special keys.
💭 There are lots of other ways of inputting special letters and symbols, but they all have drawbacks. We can change keyboard layouts on the fly, but that requires us to learn where the keys are on the other layout. We can use a multilingual layout, but that’s not configurable, and I find that some of the symbols are in surprising places. In Emacs, we can use something like abbrevs or
counsel-unicode-char, but that’s software specific. For occasional entry of special letters, I find that XCompose is just discoverable and configurable enough.
TLDR Enable the compose key in your desktop environment, and immediately get access to the accents and diacritics common in European languages (and some other goodies). See the default list of key combos here. Personalize it with