Linux add keyboard layout

How do I change keyboards from the command line?

How I change keyboard layouts from the command-line? For example, I want to switch from English to Hebrew. I’m able to do it from lightdm with the little icon in the corner of my screen.

11 Answers 11

You can find all the different keymaps in the following locations:

/usr/share/keymaps/i386/ /usr/share/kbd/keymaps/i386/ /usr/share/X11/xkb/symbols/ 

To change the keyboard layout (e.g. to Spanish) in the Linux command line, type the following command:

To make these changes system wide, assuming you’re using Ubuntu, you can use the following:

sudo dpkg-reconfigure console-setup 

This has effect on tty1, tty2, etc, but no effect in X. I want to do it in X, the same way that the keyboard switcher in lightdm works.

English to Hebrew and vise versa with Alt + Shift

setxkbmap -option grp:alt_shift_toggle us,il 

You can see all locale alias with this command

More info about setxkbmap in manual

How do you find the Dvorak keyboard using this? /etc/locale.alias seems to contain a list of locales (languages), not keyboard layouts.

Ubuntu 13.10 or Later

This works better then setxkbmap with Gnome/Unity keyboard layout indicator.

gsettings set org.gnome.desktop.input-sources current 0 

0 is the layout index (0 default or top layout). Layouts indexed starting from 0.

For easy use, create an alias.

@hugomg, right now I don’t have access yet to newer gnome. but you may try using dconf-editor tool and check /org/gnome/desktop/ . they may just rename it.

setxkbmap us,il -option "lv3:ralt_alt,grp:alt_shift_toggle" 

this command enable you toggle between English and Hebrew only through by right alt + shift and rescue you from left alt + shift .

There seems to be no standard CLI tool, but xkb-switch is a small open-source tool to do the job. Just tested it with Ubuntu 16.04.4 LTS and it works flawelessly.

$ xkb-switch # display current group ua $ xkb-switch -l # list groups us ua $ xkb-switch -s us # switch to a named group $ 

This looks better than the other solutions because setxkbmap ruins all options, and setxkbmap -layout , while it preserves the options, it still fails to change the taskbar indicator nor the grp_led if set.

Читайте также:  Linux truncate file beginning

Caveat

If your ~/.config/kxkbrc uses LayoutLoopCount (e.g. it is set to less than the total number of layouts listed in LayoutList ), like this:

LayoutList=us,ua,th,de LayoutLoopCount=2 Options=grp_led:scroll,grp:rwin_switch,compose:menu,lv3:ralt_switch, nbsp:level2,grp:rctrl_toggle,misc:typo 

then xkb-switch would only let you switch between the layouts in current group.

Invoke at screen lock

Right before my screensaver turns on, I want to switch to English so that it will be easy to type my password when I get back in.

This was precisely my goal, so here’s the answer:
To do that, you only need wrap it into a script hooking to dbus-monitor like discussed here.

Using gsettings in 18.04+ with Gnome, you can both add keyboard layouts and switch between them from the command line or from the keyboard layout switcher on the desktop.

    Present keyboard layouts and options:

$ gsettings list-recursively org.gnome.desktop.input-sources org.gnome.desktop.input-sources show-all-sources false org.gnome.desktop.input-sources xkb-options ['terminate:ctrl_alt_bksp'] org.gnome.desktop.input-sources per-window false org.gnome.desktop.input-sources current uint32 1 org.gnome.desktop.input-sources mru-sources @a(ss) [] org.gnome.desktop.input-sources sources [('xkb', 'es'), ('xkb', 'no')] 
$ gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'us'), ('xkb', 'no'),('xkb','gr')]" $ gsettings get org.gnome.desktop.input-sources sources [('xkb', 'es'), ('xkb', 'no'), ('xkb', 'gr')] 
$ gsettings set org.gnome.desktop.input-sources current 1 
cat //usr/share/X11/xkb/rules/base.lst 
$ gsettings get org.gnome.desktop.wm.keybindings switch-input-source ['space'] 

A new shortcut can be set by using gsetting set , but take care not to use a shortcut that is already in use. To list all shortcuts in use:

$ gsettings list-recursively org.gnome.desktop.wm.keybindings org.gnome.desktop.wm.keybindings cycle-windows-backward ['Escape'] org.gnome.desktop.wm.keybindings minimize ['h'] org.gnome.desktop.wm.keybindings move-to-workspace-7 @as [] org.gnome.desktop.wm.keybindings move-to-workspace-8 @as [] org.gnome.desktop.wm.keybindings move-to-workspace-9 @as [] org.gnome.desktop.wm.keybindings move-to-monitor-left ['Left'] . 

This part doesn’t seem to work on Ubuntu 23.04 with Wayland: gsettings set org.gnome.desktop.input-sources current 1

For Ubuntu 18.04 + Gnome the other answers did not work for me, but this did:

gdbus call --session --dest org.gnome.Shell \ --object-path /org/gnome/Shell \ --method org.gnome.Shell.Eval \ "imports.ui.status.keyboard.getInputSourceManager().inputSources[0].activate()" 

The argument in «inputSources[0]» is the index of the keyboard layout, the same as for gsettings solution.

Thanks. Small nit-pick, there is to such thing as «Ubuntu 22», you either meant «Ubuntu 22.04» (released in April 2022) or «Ubuntu 22.10» (released in October 2022). The version numbers are confusing, but they refer to the year and month of the date of release.

Читайте также:  Linux перечитать таблицу разделов

I was able to find the best and most stable combination of xkb-switch , setxkbmap and ibus . IBus allows pinyin input and xkb-switch is stable, while setxkbmap returns back set of keyboard layouts.

This is important when switching directly to a language, for example Shift + Alt + 1 . 4 . Why not using only IBus? It gets stuck all the time because it requires a restart to bring keyboard layouts back to life after switching to non-latin keyboard layout. At least in FireFox, see I need to exit and restart ibus-daemon to make ibus-chewing work. #2319.

Disclaimer: Tested on OpenSuse Leap 15.3 xfce4 and xkb-switch is compiled from source

To make this work you should make script files with those commands and assign keyboard shortcuts to run them. Also you might want to disable Alt+Shift shortcut in keyboard switch settings to remove unexpected behavior.

So, here are my set of commands:

Shift + Alt + 1 — switch to English:

killall ibus-daemon setxkbmap us,ru,pt xkb-switch -s us 

Shift + Alt + 2 — switch to Russian:

killall ibus-daemon setxkbmap us,ru,pt xkb-switch -s ru 

Shift + Alt + 3 — switch to Chinese Mandarin Pinyin:

ibus-daemon -d ibus reset-config gsettings set org.freedesktop.ibus.general preload-engines "['libpinyin']" setxkbmap us,ru,pt xkb-switch -s us ibus engine libpinyin 

Shift + Alt + 4 — switch to Portugese:

killall ibus-daemon setxkbmap us,ru,pt xkb-switch -s pt 

Also assign the following script to run on system autostart.

Источник

Использование других раскладок клавиатуры

Существуют сотни различных раскладок клавиатуры для разных языков. Часто даже для одного языка есть несколько раскладок, таких как раскладка Dvorak для английского языка. Можно сделать так, чтобы ваша клавиатура действовала как клавиатура с другой раскладкой, независимо от того, какие буквы и символы нанесены на клавиши. Это удобно, если вы часто переключаетесь между различными языками.

  1. Откройте Обзор и начните вводить: Настройки .
  2. Нажмите на Настройки .
  3. Нажмите Клавиатура на боковой панели, чтобы открыть этот раздел настроек.
  4. Нажмите кнопку + в разделе Источники ввода , выберите язык, связанный с раскладкой, затем выберите раскладку и нажмите Добавить .
Читайте также:  Изменить внешний вид linux mint

Если в вашей системе несколько учётных записей пользователей, на экране входа в систему для каждой будет отдельный экземпляр панели Регион и язык . Нажмите кнопку Экран входа вверху справа, чтобы переключиться между двумя экземплярами.

Некоторые редко используемые варианты раскладки клавиатуры по умолчанию недоступны при нажатии кнопки + . Чтобы сделать доступными и эти источники ввода, вы можете открыть окно терминала, нажав Ctrl + Alt + T , и запустить эту команду:

gsettings set org.gnome.desktop.input-sources show-all-sources true

Получить предварительный просмотр любой раскладки с помощью изображения можно, выбрав её в списке Источников ввода и нажав

Некоторые языки предлагают дополнительные параметры настройки. Отличить такие языки можно по дополнительному значку . Для доступа к этим дополнительным параметрам выберите язык из списка в Источниках ввода , и появившаяся кнопка даст доступ к этим настройкам.

При использовании нескольких раскладок можно выбрать, должны ли все окна использовать одну и ту же раскладку, или для каждого окна можно выбирать отдельную раскладку. Использование отдельных раскладок для каждого окна удобно, например, если вы пишете статью на другом языке в окне текстового редактора. При переключении между окнами выбранная вами раскладка будет запоминаться для каждого окна. Нажмите кнопку Параметры чтобы указать, как именно обрабатывать несколько раскладок.

В верхней панели показывается краткий идентификатор текущей раскладки, например, en для стандартной английской раскладки. Нажмите на индикатор раскладки и выберите в меню нужную раскладку. Если у выбранного языка есть дополнительные параметры, они будут показаны под списком доступных раскладок. Здесь даётся короткий обзор параметров. Для дополнительной справки можно также открыть изображение текущей раскладки клавиатуры.

Проще всего сменить раскладку можно с помощью Источник ввода Комбинации клавиш . Эти комбинации клавиш открывают выбор Источника ввода , по которому можно передвигаться назад и вперёд. По умолчанию, переключиться на следующий источник ввода можно с помощью Super + Пробел , а на предыдущий — с помощью Shift + Super + Пробел . Вы можете изменить эти комбинации клавиш в параметрах Клавиатура в разделе Комбинации клавиш ▸ Настроить комбинации клавиш ▸ Ввод .

Источник

Оцените статью
Adblock
detector