The Compose Key

A nice thing about the X Window System is that it provides a very convenient and intuitive method for inputting various characters that may not be found on the keyboard. Once you've used the Compose Key, your days of fiddling with the character map are over!

Setting up the Compose Key

First, pick a key you don't use often. Often people use the right logo key, but since I don't have one, I'll use the right Alt.

In the terminal run the command xev.

This should bring up a small window. Press the key you want. Following the key press, you'll see output like this printed on the console:

KeyRelease event, serial 34, synthetic NO, window 0x3000001,
root 0x1a6, subw 0x0, time 120807921, (-138,567), root:(795,592),
state 0x8, keycode 108 (keysym 0xff20, Alt_R), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False

You're interested in the keycode value.

Now, open ~/.Xmodmap file (if you don't have one, create it) and add the following line (replace 108 is the value you got above):

keycode 108 = Multi_key

Now run xmodmap ~/.Xmodmap. The key you've selected is now the Compose Key.

Using the Compose Key

Now you can enter various special characters by pressing (but NOT holding) the key and then a sequence. For example to create ô you press Compose, then ^, then o.

Here are some examples:

Compose ' e = é
Compose ` a = à
Compose ^ o = ô
Compose " i = ï
Compose - > = →

There are thousands (I'm not exaggerating!) of other Compose sequences. There are a few websites documenting them; however, the best way to see which exact sequences are available on your computer is by checking the file from which they are loaded: /usr/share/X11/locale/en_US.UTF-8/Compose. You're interested in the lines starting with <Multi_key>.

Creating Compose sequences

Although there are thousands of available sequences, there are more than a hundred thousand characters in Unicode, so there may be a few that you like but are missing a sequence. Or you might find an existing sequence awkward and want to change it to something easier to type.

Doing that is easy - all you need to do is create a file ~/.XCompose (note the capitalization) and put your sequence in the style of /usr/share/X11/locale/en_US.UTF-8/Compose. For example, let's say you want to add the Unicode snowman with a sequence Compose SNOW. Put the following in ~/.XCompose:

include "/usr/share/X11/locale/en_US.UTF-8/Compose"
<Multi_key> <S> <N> <O> <W> : "☃" U2603

The first line loads the pre-existing sequences so that your local .XCompose does not just override it. The second line contains the sequence, in this case capital S, N, O and W. After the colon is the character itself in quotes followed by the Unicode code point.

Once you save it (you obviously want to save it with UTF-8 encoding), all newly started applications will accept the new sequence.

Additional Resources

Alternative .XCompose file

Wikipedia entry on the Compose Key

Last modified: December 07 2009 02:18:19 GMT