How can I add a custom compose key sequence?

  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.


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.


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:

  • https://wrgms.com/using-xcompose-with-chrome-and-sublime-text/

About custom compose key sequences:

  • http://manpages.ubuntu.com/manpages/trusty/man5/XCompose.5.html
  • https://help.ubuntu.com/community/ComposeKey

About custom keyboard mapping:

  • https://help.ubuntu.com/community/Custom%20keyboard%20layout%20definitions

Example .Xcompose files to mimic Window US International keyboards:

  • https://gist.githubusercontent.com/guiambros/b773ee85746e06454596/raw/0ea6d7f7cf9a6ff38b4cafde24dd43852e46d5e3/.XCompose
  • http://pastebin.com/vJg6G0th