Misc / How To Type Unicode On Linux

I often want to type characters which aren’t on my keyboard, especially when writing HTML, characters such as: curly quotes, thin spaces, copyright symbols, em dashes, etc. In the past I would resort to using the HTML entities, e.g. —, but as all my HTML files are encoded in UTF-8 it makes sense to type them directly, X11 makes that easy.

You simply assign a key on your keyboard to act as a “compose key”, I use AltGr, but you can the Windows key, the menu key, caps lock, or any key you don't make use of. To set the AltGr key as your compose key type setxkbmap -option compose:ralt in your terminal, and/or put it in ~/.xinitrc to make it permanent. That’s it! You can press your compose key and then type 12 to get ½, or <3 to get ♥, or !? to get ‽. It’s as simple as that.

There are thousands of combinations preloaded, and most of them are very intuitive. You can see the full list in /usr/share/X11/locale/en_US.UTF-8/Compose. It’s also easy to add your own combinations, just place them in ~/.XCompose, restart the application you want to use them in and you’re good to go.

Here’s my basic ~/.XCompose which extends the defaults:

include "/usr/share/X11/locale/en_US.UTF-8/Compose"

# EMOTICONS
<Multi_key> <o> <underscore> <o>               : "ಠ_ಠ" # LOOK OF DISAPPROVAL
<Multi_key> <colon> <D>                        : "😃"   # :D
<Multi_key> <semicolon> <parenright>           : "😉"   # ;)
<Multi_key> <colon> <p>                        : "😛"   # :p
<Multi_key> <semicolon> <p>                    : "😜"   # ;p
<Multi_key> <colon> <bar>                      : "😐"   # :| 
<Multi_key> <colon> <apostrophe> <parenright>  : "😢"   # :'( 

# PUNCTUATION
<Multi_key> <bracketright> <apostrophe> : "’"   U2019    # RIGHT SINGLE QUOTATION MARK
<Multi_key> <bracketleft> <apostrophe>  : "‘"   U2018    # LEFT SINGLE QUOTATION MARK
<Multi_key> <bracketright> <quotedbl>   : "”"   U201d    # RIGHT DOUBLE QUOTATION MARK
<Multi_key> <bracketleft> <quotedbl>    : "“"   U201c    # LEFT DOUBLE QUOTATION MARK
<Multi_key> <space> <t>                 : " "   U2009    # THIN SPACE
<Multi_key> <space> <m>                 : " "   U2003    # EM SPACE

# GREEK
<Multi_key> <g> <A>    : "Α"   U0391    # GREEK CAPITAL LETTER ALPHA
<Multi_key> <g> <a>    : "α"   U03B1    # GREEK SMALL LETTER ALPHA
<Multi_key> <g> <B>    : "Β"   U0392    # GREEK CAPITAL LETTER BETA
<Multi_key> <g> <b>    : "β"   U03B2    # GREEK SMALL LETTER BETA
<Multi_key> <g> <D>    : "Δ"   U0394    # GREEK CAPITAL LETTER DELTA
<Multi_key> <g> <d>    : "δ"   U03B4    # GREEK SMALL LETTER DELTA
<Multi_key> <g> <E>    : "Ε"   U0395    # GREEK CAPITAL LETTER EPSILON
<Multi_key> <g> <e>    : "ε"   U03B5    # GREEK SMALL LETTER EPSILON
<Multi_key> <g> <F>    : "Φ"   U03A6    # GREEK CAPITAL LETTER PHI
<Multi_key> <g> <f>    : "φ"   U03C6    # GREEK SMALL LETTER PHI
<Multi_key> <g> <G>    : "Γ"   U0393    # GREEK CAPITAL LETTER GAMMA
<Multi_key> <g> <g>    : "γ"   U03B3    # GREEK SMALL LETTER GAMMA
<Multi_key> <g> <H>    : "Η"   U0397    # GREEK CAPITAL LETTER ETA
<Multi_key> <g> <h>    : "η"   U03B7    # GREEK SMALL LETTER ETA
<Multi_key> <g> <I>    : "Ι"   U0399    # GREEK CAPITAL LETTER IOTA
<Multi_key> <g> <i>    : "ι"   U03B9    # GREEK SMALL LETTER IOTA
<Multi_key> <g> <J>    : "Θ"   U0398    # GREEK CAPITAL LETTER THETA
<Multi_key> <g> <j>    : "θ"   U03B8    # GREEK SMALL LETTER THETA
<Multi_key> <g> <K>    : "Κ"   U039A    # GREEK CAPITAL LETTER KAPPA
<Multi_key> <g> <k>    : "κ"   U03BA    # GREEK SMALL LETTER KAPPA
<Multi_key> <g> <L>    : "Λ"   U039B    # GREEK CAPITAL LETTER LAMDA
<Multi_key> <g> <l>    : "λ"   U03BB    # GREEK SMALL LETTER LAMDA
<Multi_key> <g> <M>    : "Μ"   U039C    # GREEK CAPITAL LETTER MU
<Multi_key> <g> <m>    : "μ"   U03BC    # GREEK SMALL LETTER MU
<Multi_key> <g> <N>    : "Ν"   U039D    # GREEK CAPITAL LETTER NU
<Multi_key> <g> <n>    : "ν"   U03BD    # GREEK SMALL LETTER NU
<Multi_key> <g> <O>    : "Ο"   U039F    # GREEK CAPITAL LETTER OMICRON
<Multi_key> <g> <o>    : "ο"   U03BF    # GREEK SMALL LETTER OMICRON
<Multi_key> <g> <P>    : "Π"   U03A0    # GREEK CAPITAL LETTER PI
<Multi_key> <g> <p>    : "π"   U03C0    # GREEK SMALL LETTER PI
<Multi_key> <g> <Q>    : "Χ"   U03A7    # GREEK CAPITAL LETTER CHI
<Multi_key> <g> <q>    : "χ"   U03C7    # GREEK SMALL LETTER CHI
<Multi_key> <g> <R>    : "Ρ"   U03A1    # GREEK CAPITAL LETTER RHO
<Multi_key> <g> <r>    : "ρ"   U03C1    # GREEK SMALL LETTER RHO
<Multi_key> <g> <S>    : "Σ"   U03A3    # GREEK CAPITAL LETTER SIGMA
<Multi_key> <g> <s>    : "σ"   U03C3    # GREEK SMALL LETTER SIGMA
<Multi_key> <g> <T>    : "Τ"   U03A4    # GREEK CAPITAL LETTER TAU
<Multi_key> <g> <t>    : "τ"   U03C4    # GREEK SMALL LETTER TAU
<Multi_key> <g> <U>    : "Υ"   U03A5    # GREEK CAPITAL LETTER UPSILON
<Multi_key> <g> <u>    : "υ"   U03C5    # GREEK SMALL LETTER UPSILON
<Multi_key> <g> <W>    : "Ω"   U03A9    # GREEK CAPITAL LETTER OMEGA
<Multi_key> <g> <w>    : "ω"   U03C9    # GREEK SMALL LETTER OMEGA
<Multi_key> <g> <X>    : "Ξ"   U039E    # GREEK CAPITAL LETTER XI
<Multi_key> <g> <x>    : "ξ"   U03BE    # GREEK SMALL LETTER XI
<Multi_key> <g> <Y>    : "Ψ"   U03A8    # GREEK CAPITAL LETTER PSI
<Multi_key> <g> <y>    : "ψ"   U03C8    # GREEK SMALL LETTER PSI
<Multi_key> <g> <Z>    : "Ζ"   U0396    # GREEK CAPITAL LETTER ZETA
<Multi_key> <g> <z>    : "ζ"   U03B6    # GREEK SMALL LETTER ZETA

Last updated on .