
Our computers can display an astonishing range of symbols. Unicode alone defines more than 150,000 characters, covering everything from mathematical operators and phonetic alphabets to emoji and obscure historical scripts. Our keyboards, on the other hand, remain stubbornly limited to a few dozen keys.
On Windows, the traditional workaround involves memorizing numeric codes or digging through character maps. Linux, being Linux, offers something far more flexible: XCompose. It’s one of those powerful, quietly brilliant features that’s been around forever, works almost everywhere, and somehow still feels like a secret.
XCompose is part of the X11 input system. It lets you define compose sequences: short key sequences that produce a Unicode character. Think of it as a programmable “dead key” system on steroids. This can be as simple as programming an ‘E’ to produce a Euro sign or as complex as converting “flower” into a little flower emoji. Even though the system originated with X11, I’ve been told that it mostly works with Wayland, too. So let’s look deeper.
Starting XCompose
The secret is the Compose or Multi-key. You press it to essentially escape into XCompose mode, so when you type “flower”, it knows you don’t want to insert those literal letters in. You can pick which keyboard key is your compose key in your system settings. The Right Alt or Ctrl key is a common choice. I use my Caps Lock key, since I never really use it for anything else.
You can set the Compose key in other ways, too, including in ~/.XCompose, but it is usually easier to set it in the system settings. However, ~/.XCompose is one place you can set up custom rules.
By default, though, you should have some useful combos. For example, <Compose> ’ e it should give you é and <Compose> " o should give you ö. The default rules are in /usr/share/X11/locale/*/Compose, where the * is your locale of choice.
Customize
The defaults usually cover a lot of ground. But you may want to define your own. You can do that by creating or editing ~/.XCompose. This file can contain rules or include other rule files. I have heard, however, that Wayland doesn’t do includes, so if you use that, it is something to keep in mind.
The file format is simple enough, with each line being a definition:
<Multi_key><a><e> : “æ”
Don’t make the mistake of trying to write something like <@>. All the special characters need the names from X11’s keysymdef.h file like <at> or <asterisk>.
When you make a custom file, you’ll usually start with:
include “%L”
This tells the system to load the defaults for your locale. You can also use %H for your home directory or %S for the system directory. When using some systems, you may have to include “/%L” instead.
Formally, the configuration line looks like this:
<EVENT>… : <RESULT> # comment
The <EVENT> allows you to not only specify keys but also modifiers that must be or must not be present. The <RESULT> can be a string or a character, and you can even insert an octal or hex number to be sure you get the key you want. For more, read the man page.
It is worth noting that any definition you provide will override the system ones, so if you don’t like something, it is easy to redefine it to something else. One nice thing is that the result doesn’t have to be a single character. You can use an entire string system. So:
<Multi_key> <c> <q> : “CQ de WD5GNR K”
As far as I know, there’s no way to embed a newline in the result that always works. You can try using something like \xa, for example, but \n doesn’t work. Also, no substitutions work on password/PIN entry, and that’s by design.
Why Build Your Own?
You can build up strings that make sense to you. But you know someone’s already done it. The repo has a core file of interesting definitions and some extra ones, too. My suggestion: don’t use their install function, which only gives you the core. Just create your own file like this, adjusting for wherever you put the files:
include “%L”
include “/home/xxx/xcompose/dotXCompose” include “/home/xxx/xcompose/frakturcompose” include “/home/xxx/xcompose/emoji.compose” include “/home/xxx/xcompose/modletters.compose” include “/home/xxx/xcompose/parens.compose”
Keep in mind that when you change this file, it will only apply to GUI apps you started after the change. Try <Compose> : ) to get
among others.
And if you don’t like that collection, there are others.
Some Common Use Cases
Music? Try ♭ (#b) or ♯ (##). You can even make notes like ♪ (#e). Prefer math? How about ≠ (/=) or a square root symbol √ (v/). If your math runs more to accounting, you can write about Euros (€ – =E) or Yen (¥ – =Y). Hams will appreciate /O which produces Ø (note, that is an upper case O on the input).
There are plenty of other ones, too. The best way to know is to look in the files you are using and experiment.
<Multi_key> <3> <3> : “¯_(ツ)_/¯” # Shrug
It is easy to code up things like your name, your e-mail address, and more. Since you can use names instead of cryptic keystrokes, it is much easier to use. For example, I forget that my name is on Macro+F5, but <Compose>@name is easy to remember. I find it makes it easy to remember if I prefix all (or most of ) my personal commands with some character like “@.” So I might have @name, @add, @tel, and @email, for example. Just don’t forget, the actual rules have to use the key names:
<Multi_key><at><n><a><m><e>:“Al Williams”
Some applications, notably GTK apps, won’t work with XCompose without some tweaking. In particular, you may need to override the default input method. If this problem bites you, a quick search for “XCompose and GTK” should give you some advice. There’s always a chance your app, or even some input fields in your app, won’t work with XCompose. That’s life.
What It Isn’t
Keep in mind that XCompose only works in the GUI. It isn’t context-aware. It doesn’t allow you to insert multiple lines. If you need scripting and other advanced features, this isn’t the right place to be. Want to just map keys sometimes? You can do it, but not with this tool.
But for nearly universal keyboard remappings, it works quite well, once you get used to the syntax. Have a favorite line in your .XCompose? Share it in the comments!
From Blog – Hackaday via this RSS feed


