NeoVim and Keyboard Layouts
Various methods for handling keyboard layouts in NeoVim
Ivan Elfimov, 2023-09-04, 2m (358 words)
It is strange how English became defacto for all computer things. Or maybe not so strange. Regardless, the real life scenario for a lot of people is using two or more keyboard layouts at the same time. And I am one of those as well. This is my summary of “A State of Layouts” in (Neo)Vim ecosystem.
The Nothing approach
First of all, you don’t have to do anything special. If you want to switch the layout, you switch it manually when necessary. Most of vimmers I know don’t bother. I guess I only have one tip in that case: use one-key switching, ex. bind CapsLock
in your system input settings.
langmap
The idea is to map the specific or the entire range of English letters into your target language:
set langmap=АБВГД;abcde
The downside is that you still have to switch the layout when you want to type something in insert mode.
keymap
This is a slight upgrade to langmap
. Instead, the map is defined on a keymap
level. The most common keymaps for English/Russian setup is:
set keymap=russian-jcukenwin
set keymap=mac-russian-colemak
But the downsides are still the same. Plus these keymaps will probably break your muscle memory in some cases.
Plugins
Entering the plugin world. These require a bit of a setup, but after that they all work perfectly.
When I used Vim
(before NeoVim
), I tried lyokha/vim-xkbswitch, which works well on MacOSX together with vovkasm/input-source-switcher. The installation instructions are straightforward and quite simple.
After I switched to NeoVim
I changed almost all of my plugins to Lua alternatives. Layout switching plugin was no exception. The one I use now is ivanesmantovich/xkbswitch.nvim. It still requires input-source-switcher. The only thing I had to do to make it work is to change my ABC
layout to U.S.
layout, because of the hardcoded regexes. I wanted to move from hardcoded stuff and even submitted a PR, but it was closed and considered not inline with the repo philosophy, oh well.
The config is minimal:
{
"ivanesmantovich/xkbswitch.nvim",
config = function()
require("xkbswitch").setup({})
end
}
I think xkbswitch.nvim
is the best approach when working with multiple keyboard layouts and you should definetely try it!
More posts in NeoVim Config series:
- Saving pixels in NeoVim 2024-03-16
- NeoVim Telescope Keymap Mnemonic 2023-12-07
- Plugins from Trixy NeoVim distro 2023-09-17
- New NeoVim plugin - mini.clue 2023-08-04
- Not so obvious NeoVim key mappings 2023-07-21
- New series: NeoVim config 2023-07-20