Linux – US International keyboard layout on Linux that mimics Windows’ behavior

gnomeinternationalkeyboard-layoutlinux

I am used to using US International as my keyboard layout. However, the implementation appears to differ greatly between Windows and Linux (Gnome, in my case – may well be a GTK issue since GTK behaves the same on Windows).

The layout uses dead keys, for example for keys such as ', ", ^, &c. allowing easy entry of characters with diacritics. On Windows pressing a dead key and then a key that has no pair associated results in the dead key's character (when paired with space) and the character from the second key. Example: Pressing ", a yields “ä”, however, pressing ', s yields “'s”, as there is no pairing for ' and s.

Now, there is a language called English which makes frequent use of exactly those two characters and since it works on Windows to just type them as usual it's muscle memory for me now. Which brings me to my problem:

On Linux (and GTK on Windows), there is a pairing for ' and s (among many others), resulting in ś (which, in turn, leads to me frequently typing “itś”). So typing “it's” requires me to type ',         , s at the end.

There are a few other combinations I'm used to that don't work. Among those is that for non-existant pairs simply nothing is the result. Typing “I'd” results in “I”. Hitting one of those keys twice results in a non-spacing diacritic which breaks my habit of typing strings by first typing both quotation marks (which now result in a non-spacing acute accent or macron).

Long story short: None of the supplied US International layouts appears to function the same as in Windows – are there any that do work identically? Or any chance to configure it that way? While it may be nice to type an s with acute accent or non-spacing diacritics, those aren't exactly common needs for me.

Best Answer

One possibility is to avoid having dead keys and type accented letters with a Compose key instead. For example, type Compose " a to enter ä. You'll have to choose a keyboard layout option that includes a Compose key; a common choice is the key to the left of the right Ctrl key (which I think Windows calls Menu). The advantage of Compose is that you get to be able to type many fancy characters without changing your main layout. The disadvantage is that it takes three presses instead of two for an accented letter.

Alternatively, you can configure the effect of dead keys by creating a file called .XCompose (note CApitalization) in your home directory and listing the combinations you want. Something like:

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

<dead_acute> <space> : "'" apostrophe
<dead_acute> <exclam> : "'!"
<dead_acute> <quotedbl> : "'\""
# etc...
<dead_acute> <a> : "á"
<dead_acute> <b> : "'b"
# etc...

The syntax is fairly simple: the sequence of keys to the left of the : is turned into the string between "" on the right of the :. The extra word on the right is the keysym (i.e., the name of the key) corresponding to this sequence of keys; it's not terribly important. Anything from a # to the end of the line is ignored.

Change the first line to point to the system file if your distribution puts it in a different place. You can look in this file for more syntax examples. <Multi_key> is another name for the Compose key.

On the left, the names between <angle brackets> are keysyms. You can find the list of keysyms in /usr/include/X11/keysymdef.h (this file is in a development package, e.g., x11proto-core-dev on Ubuntu).

Yes, that's a lot of typing, but you should be able to automate much of it by copy-pasting chunks of keysymdef.h and doing a few clever mass replacements. Something that will help is that you can reuse the hexadecimal code on the right to make the right-hand string thanks to the "\xdd" syntax: turn e.g.

#define XK_exclam                        0x0021  /* U+0021 EXCLAMATION MARK */

into

<dead_acute> <exclam> : "'\x21"

Finally, you can set up a keyboard layout with dead keys and a Compose key. Being German, you might set up only " as a dead key. If you're going that route, the simplest option is to use the GUI to set up a keyboard with no dead key and an .Xmodmap file for the dead key, containing something like

keysym apostrophe = apostrophe dead_quotedbl
Related Question