3 min read

Keyboard layouts in Linux

Sometimes, you may need to use several keyboard layouts, but one of them is rarely used. For example, I use Russian, English, and Ukrainian layouts, but I rarely need the Ukrainian one. Cycling through layouts to find the needed one isn’t always convenient, and toggling the indicator without looking can be tricky. Manually adding and removing the Ukrainian layout every time is also inconvenient.

A simple solution to this problem is to extend the primary layout by adding five additional characters from the Ukrainian layout. First, in the keyboard layout settings, select a key for accessing third-level symbols.

Keyboard

Editing the Layout Configuration

Next, modify the layout configuration file. In this example, I will add Ukrainian characters to the primary layout so that pressing Win + “ы” outputs the letter “і”.

sudo vi /usr/share/X11/xkb/symbols/ru

Note that the path to the layout configuration files may vary depending on your Linux distribution. This file contains mappings of keys to output characters. The square brackets define key mappings:

  • The first value represents the lowercase character.
  • The second value represents the uppercase character (Shift).
  • The third value corresponds to the third-level key.
  • The fourth value represents Shift + third-level key.

By default, the “ы” and “Ы” keys have predefined values. Modify them as follows:

key <AC02> { [ Cyrillic_yeru, Cyrillic_YERU, Ukrainian_i, Ukrainian_I ] };

Now pressing Win + “ы” will produce “і” and pressing Shift + Win + “ы” will produce “І”.

Similarly, locate and modify the other five required keys:

key <AD12> { [ Cyrillic_hardsign, Cyrillic_HARDSIGN, Ukrainian_yi, Ukrainian_YI ] };
key <AC02> { [ Cyrillic_yeru, Cyrillic_YERU, Ukrainian_i, Ukrainian_I ] };
key <AC11> { [ Cyrillic_e, Cyrillic_E, Ukrainian_ie, Ukrainian_IE ] };
key <AD07> { [ Cyrillic_ghe, Cyrillic_GHE, Ukrainian_ghe_with_upturn, Ukrainian_GHE_WITH_UPTURN ] };
key <TLDE> { [ Cyrillic_io, Cyrillic_IO, apostrophe ] };

Final Mappings

Now, you can use Ukrainian characters by pressing Win along with the corresponding key:

  • і = Win + ы
  • ї = Win + ъ
  • ` = Win + ё
  • ґ = Win + г
  • є = Win + э