I sometimes want to write special Unicode characters, like an em-dash (—), in various programs like vim, Chrome (like just now!), or LibreOffice.

In LibreOffice, I can achieve this via a dedicated dialog box found under the Insert menu. Other programs don't seem to have a built-in way. My solution in these cases is to look up the character on Wikipedia, copy it, and paste it in.

Is there a universal way to write Unicode characters in any program that accepts text input in Linux without having to copy and paste from somewhere where it's already printed?

  • You could have search for "Unicode input" on Wikipedia. Now mentioned in my answer. – vinc17 Feb 17 '15 at 22:26
  • In LibreOffice (and MS Office) there is also a list of automatic substitutions, like (C) -> ©. Quite often, people configure -- as en-dash and --- as em-dash. – Simon Richter Feb 17 '15 at 23:17
  • Is there a universal way... No. (I'm not aware of a "universal" way to do anything via programming.) – user2338816 Feb 18 '15 at 4:44

Either you can enable an Compose key, or you can press CtrlShiftU followed by the Unicode hexadecimal number of the character (leading zeroes can be skipped). For example, Æ is CtrlShiftU, then C6. This works on GNOME Terminal, Terminator, Google Chrome and a number of other applications, with Xterm (and according to comments, Emacs) not working.

On GNOME, to enable Compose, go to the Keyboard settings, then ShortcutsTypingAlternative Characters Key and map it to something (say, Right Alt). Then you press the Compose key, and - thrice to get an em-dash: —. (The arrows in this paragraph are all Compose->.)

enter image description here

  • 2
    The Ctrl+Shift+u solution doesn't work in Xterm and in Emacs. It doesn't work in Firefox either. – vinc17 Feb 17 '15 at 21:04
  • 2
    @vinc17 it does work in Firefox for me. I have neither Xterm or Emacs to test on. – muru Feb 17 '15 at 21:09
  • Hmmm, yes, it works in Firefox, but I have to type the Space key after the hexadecimal sequence. In any case, this is not universal, but probably a feature added by some applications (or some window managers?). Also, it doesn't work in Opera. – vinc17 Feb 17 '15 at 21:11
  • AltGr is just a modifier to get additional key combinations. This is what I use to enter the characters listed in my answer (e.g. Shift+AltGr+[ gives ←). But the user can also map characters to other keys such as function keys; this is what I do to get the French accented characters: éèêëâîôûàùïç. Everything done via XKB settings. – vinc17 Feb 17 '15 at 21:21
  • @vinc17 I made an epic fail. I was talking about Compose and said AltGr instead. – muru Feb 17 '15 at 21:27

The best way is still to type the character on your keyboard. Thanks to XKB, you can bind arbitrary Unicode characters to key combinations. For instance, with user XKB customization, I can type directly: ← → ↑ ↓ … € ½ « » — − ± ≠ ∩ ∪ ⊂ ∧ ∨ ∀ ∃ √ ∞ ≤ ≥, etc.

Note: in the particular case of GNU Emacs, Unicode composition can be done via Ctrlx+8+Return. See Ctrlx+8+Ctrlh for additional methods.

"Unicode input" on Wikipedia gives information about ISO 14755 Unicode input depending on the context, in particular for X11 with some toolkits and for specific applications (Emacs, Opera, Vim).

Alternatively, you can use the Compose key with user-defined settings (as the default settings are far from being complete). Documentation is provided by the Compose(5) man page. For instance, write a file $HOME/.XCompose containing:

include "%L"
<Multi_key> <bracketleft> <c>           : "⌈" U2308 # LEFT CEILING
<Multi_key> <bracketright> <c>          : "⌉" U2309 # RIGHT CEILING
<Multi_key> <bracketleft> <f>           : "⌊" U230A # LEFT FLOOR
<Multi_key> <bracketright> <f>          : "⌋" U230B # RIGHT FLOOR

The include "%L" line first loads the default (locale-specific) Compose file, and the next four lines add user-defined settings, such as: Compose+[+c gives the left-ceiling character "⌈" (U+2308).

  • You don't need XKB to bind Unicode characters to key combinations, you can also do it with xmodmap. You won't be able to reach all Unicode characters that way though, there are just too many. – Gilles Feb 17 '15 at 22:27
  • 1
    @Gilles xmodmap is not as powerful as XKB and I had problems with it in the past. Hence my switch to XKB. Moreover I don't use all Unicode characters. For rare characters, an on-screen picker may be the best solution, because one may not know their codepoint and how to enter them. – vinc17 Feb 17 '15 at 22:49
  • I don't understand how do you enter ∩ ∪ ⊂ ∧ ∨ ∀ with compose. The rest « » € ₤ ö etc. works. But not the math symbols. – Igor Chubin Jan 27 '18 at 9:28
  • @IgorChubin I do not use compose, just ISO_Level3_Shift (a.k.a. AltGr). I've just edited my answer to give a link to my web page explaining user XKB customization. – vinc17 Jan 28 '18 at 2:17
  • @vinc17 Thank you, I will read more about it. Do you know any advantages of this method comparing to compose? – Igor Chubin Jan 28 '18 at 16:16

As described in detail in this post, there's a great way to do add unicode keys without having to remember any awkward key combinations or use any drop down menus.

It boils down to using Autokey, which can take any set of key strokes as a trigger to run a script or paste a phrase. In this case, your phrase is simply the unicode character you want.

As the post describes, a good way to do it is to follow LaTeX, but with a forward slash rather than backslash. For example, typing /delta anywhere (browser, libre office, etc) will automatically get converted to δ.

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.