How can I add a custom compose key sequence?

For example, I would like Compose, |, > to type the symbol.

I have tried adding the following to ~/.XCompose:

# Import default rules from the system Compose file
include "%L"

# Custom definitions
<Multi_key> <bar> <greater> : "▸" U25B8 # Black right-pointing small triangle

but the new sequence is not usable anywhere except for xterm.

Installing ibus-table-compose and then enabling the Compose input method in IBus did not solve the problem; IBus imitated many compose key sequences, but not the one I had created.

  • How do you type the symbol now? You could probably map the command you use to type the symbol to specific keys in keyboard layout. To find the exact keysym of a particular key, you can use xev . But ofcourse, this is just my guess. – Nitin Venkatesh Jun 7 '11 at 15:52
  • 3
    @nitstorm I typed it by pressing AltGr+>, which is a customized mapping that I set by adding the keysym U25B8 to keycode 60 in ~/.xmodmaprc. I'm not asking how to type ▸; I'm asking how to create a compose key sequence for it. – ændrük Jun 7 '11 at 16:05

Create a file ~/.XCompose (that is a file named .XCompose in your "home" folder) which contains the following:

include "%L"   # import the default Compose file for your locale
<Multi_key> <bar> <greater>     : "▸"

See man 5 Compose for more info about the format of this file.

  • 3
    Neat! Is there any way to have this file re-read without restarting X? – Jeremy Kerr Jun 8 '11 at 7:10
  • 1
    This sounds promising, but my ~/.XCompose file doesn't seem to have any effect even after rebooting. Have you gotten this to work? – ændrük Jun 8 '11 at 15:49
  • @Jeremy: I'm not sure, but maybe changing the keyboard layout to another layout and then back might work. – JanC Jun 9 '11 at 12:52
  • 1
    @ændrük: I seem to remember that Gtk/GNOME stupidly messes with the compose key settings (you can test if the new Compose key combination works in e.g. xterm to confirm this is the case). I seem to remember the workaround had something to do with selecting an alternative input method that bypasses the problematic medling; maybe ask a new question about that, because it's not only useful for this but IIRC it also fixes locale-specific Compose maps, etc. ;) – JanC Jun 9 '11 at 13:14
  • 1
    As of at least 18.04 LTS this answer should now work without needing to change input methods. – ændrük Nov 2 '18 at 16:30
  1. Create a file named .XCompose in your home directory (~/.XCompose), which contains:

    # import the default Compose file for your locale
    include "%L"
    <Multi_key> <bar> <greater>  : "▸"

    See man 5 Compose for more info about the format of this file.

  2. Add the following to ~/.profile:

    export GTK_IM_MODULE="xim"

    On Ubuntu 18.04 (maybe others), you may need to use the following instead:

    export GTK_IM_MODULE="gtk-im-context-simple"
  3. Log off and back on. Or restart X. Or reboot.

  • 3
    I noticed that with this solution, I cannot use Ctrl-Shift-u anymore to insert unicode characters by number; so I take it that this switches something general away from the Gnome stuff to the X stuff which is configured by that ~/.XCompose file. Is there also a way to modify the Gnome stuff instead? I'd like to keep that Ctrl-Shift-u feature. – Alfe Jan 28 '13 at 15:31
  • 2
    @Alfe Using UIM as suggested on the bottom of Ubuntu Forums: .XCompose file not read in 11.04 GNOME works for me with the default settings in Debian jessie/sid (see im-config(8) for customization). That is, .XCompose settings are working both in GTK (GNOME) and Qt (KDE) applications, and .XCompose and Ctrl+Shift+U are both working in GTK applications (like Eclipse). – PointedEars May 10 '13 at 16:22
  • Thank you! So did you just apt-get the uim package or did you have to configure something else? – Alfe May 10 '13 at 19:59
  • 1
    I tried to get this running for some time now, but to no avail. It'd be very helpful to hear what exactly you did besides installing the uim package. At least this could help to be sure that your way doesn't work on Ubuntu 12.04. – Alfe May 10 '13 at 22:32
  • @dan_waterford Hi, I just asked this question here, and had it "possible duplicate"'d to this question. However, I've tried your answer and couldn't get it to work. Any ideas? :) – Owen_AR Nov 15 '13 at 17:42

On Ubuntu 14.04 I did the following:

1) Installed uim using the Software Manager, other packages like uim-xim, uim-gtk2, uim-gtk3 and uim-qt are auto installed. See https://launchpad.net/ubuntu/+source/uim.

2) Defined environmental variables by adding the next lines to ~/.profile, this way the custom compose key sequences only apply to the current user:

# Restart the X-server after making alterations using:
# $ sudo restart lightdm
# It seems only GTK_IM_MODULE or QT_IM_MODULE needs to be defined.
export GTK_IM_MODULE="uim"
export QT_IM_MODULE="uim"

The ~/.XCompose-file from the OP should work after restarting 1) Ubuntu or 2) just the X-server by runnung the following command in a terminal:

$ sudo restart lightdm

NB: Restarting only seems necessary after altering the ~/.profile file, alterations to ~/.XCompose will take effect the next time an application (Terminal, Gedit, etc.) starts.

To check whether the environmental variables are set right, enter the following command in your terminal:

$ printenv | grep IM_MODULE

Many thanks to:

About custom compose key sequences:

About custom keyboard mapping:

Example .Xcompose files to mimic Window US International keyboards:

  • That’s what I did, but compose sequences inputs just nothing, nothing at all. – Hibou57 Apr 27 '20 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.