Typing Uralic Languages on Linux

Warning: don't change your keyboard to a non-Latin layout until you've read the section "Running setxkbmap With Non-Latin Keyboard"! If you do accidentally do this, and can't figure out how to switch back to the layout you're used to, restarting your computer will probably fix everything.

Note: I'm going to try to provide an explanation that's as distro-agnostic as possible. If you use a mainstream distro such as Ubuntu, it's possible that there are other ways of changing the keyboard layout.

Second Note: I'm also going to assume that you're familiar with the command line, and know how to open a terminal and type commands into it. If you aren't, there are many good tutorials available on the internet.

General Principles

I've found that the easiest way to change the keyboard layout on Linux is with the setxkbmap command. It requires a layout (given using the -layout flag), and optionally a variant (specified using the -variant flag). A layout can also be given as an argument without the -layout flag, but in this tutorial we will use the flag for clarity.

Thus, if you want to change your keyboard to a layout that does not require a variant (i.e. any of the layouts with "-" in the "Variant" column in the table below), you can run the following command:

setxkbmap -layout <layout>

However, to change your keyboard to a layout that requires a variant (such as the layouts for most Finno-Ugric languages written with the Cyrillic alphabet), the command will need to look like this:

setxkbmap -layout <layout> -variant <variant>

Note that both the -layout and -variant flags can take multiple arguments, given as a comma-separated list (with no spaces between the elements). Both flags must have the same number of arguments. This will come in handy later, if you want to toggle between multiple keyboard layouts.

Running setxkbmap With Non-Latin Keyboard

You basically have two options: bind the setxkbmap commands that you are planning to use to hotkeys, and/or set up multiple layouts with a key combination allowing you to switch between them. Since the first option is heavily dependent on the window manager that you use, I will only be discussing the second option here.

Common choices for the layout toggle key are the Windows keys (grp:lwin_toggle/grp:rwin_toggle), the caps lock key (grp:caps_toggle), or one of the Alt keys (grp:lalt_toggle, or just grp:toggle for the right alt key). A fuller list of options can be found by running man xkeyboard-config and scrolling down to the section OPTIONS > Switching to another layout.

To set multiple layouts with a key to toggle between them, you will need to add one more flag to your setxkbmap command: -option, which takes one or more of the previously mentioned options (use a comma-separated list if specifying multiple toggle keys) as an argument. If you need to use the -variant flag, make sure that the elements in the list given to both that and the -layout flag match, even if it means you have to leave some spaces blank. An example command might resemble the following (note that the repetition of -option is not a mistake — it will be explained later):

setxkbmap -layout fi,ru -variant ',chm' -option -option grp:lwin_toggle

Languages and Associated Layouts/Variants

The minus sign "-" indicates that no variant is necessary. Variants in parentheses are optional and generally not necessary.

Language Layout Variant
Erzya ru -
Estonian ee -, (dvorak, nodeadkeys, us)
Finnish fi -, (classic, mac, nodeadkeys, winkeys)
Hungarian hu -, (nodeadkeys, querty, standard)
Komi (both) ru kom
Mari (both) ru chm
Mokša ru -
Sámi (*) fi, no, se smi, smi_nodeadkeys (only with no layout)
Udmurt ru udm

* - technically, these are listed as being for Northern Sámi only. I can't promise that they'll work for other Sámi languages.

Compose Key

A compose key allows you to type a much larger variety of characters than those assigned keys in your keyboard layout, by combining ("composing") multiple characters. These combinations always being with a particular key (the "compose key"), which has no other function in the keyboard layout.

Common choices for the compose key are the left or right Windows key (compose:lwin/compose:rwin), the caps lock key (compose:caps), or the right alt key (compose:ralt). A fuller list of options can be found by running man xkeyboard-config and scrolling down to the section OPTIONS > Position of Compose key. Make sure you pick a different key from the one you use to toggle between layouts.

As with the layout toggling key, the compose key option must simply be added to the comma-separated list of options passed to the -option flag. For example:

setxkbmap -layout fi,ru -variant ',chm' -option -option compose:rwin,grp:lwin_toggle

Miscellaneous

When using the -option flag with arguments in a command that you will run multiple times over the course of a session (say, if you plan to use multiple layouts and want to access them by binding calls to setxkbmap to hotkeys), you should first clear the existing options by passing a blank -option flag to the command immediately before the one carrying your actual options (this is shown in all example commands where options are used). If you don't do this, calls to setkxbmap will eventually stop working (likely due to a data store filling up somewhere, although I'm unsure of the specific cause of this problem).

You should also bear in mind that setxkbmap can do a lot more than the basics mentioned here. Spend some time reading the relevant man pages (man setxkbmap, man xkeyboard-config) if you're interested.

Feel free to email me@<this site's domain name> if you have further questions, or believe I have made a mistake somewhere.