lyokha / vim-xkbswitch

vim plugin for automatic keyboard layout switching in insert mode
MIT License
481 stars 23 forks source link

Keymap assistance in Normal mode not working #62

Open mario-amazing opened 1 year ago

mario-amazing commented 1 year ago

r and f commands not working with configuration from readme:

let g:XkbSwitchAssistNKeymap = 1    " for commands r and f
let g:XkbSwitchAssistSKeymap = 1    " for search lines

XkbSwitchAssistNKeymap -> not working XkbSwitchAssistSKeymap -> working, but have deprecation messages when vim started

tried with:

set keymap=russian-jcukenwin
set iminsert=0
set imsearch=0

and

let g:XkbSwitchDynamicKeymap = 1
lyokha commented 1 year ago

How do you expect it to work? Keymap assistance won't switch system keyboard layout. Instead, it relies on builtin Vim's iminsert and imsearch attributes. So, when you returned from Insert mode with, say, Russian keyboard layout, typing fg will actually find letter п. I use dynamic keymap assistance with the following config:

let g:XkbSwitchAssistNKeymap = 1    " for commands r and f
let g:XkbSwitchDynamicKeymap = 1
let g:XkbSwitchKeymapNames =
            \ {'ru' : 'russian-jcukenwin', 'de' : 'german-qwertz'}
" quickly toggle keyboard layout for f and r commands in normal mode
" (<C-^> also switches keyboard layout in search mode)
let g:XkbSwitchIminsertToggleKey = '<C-^>'
let g:XkbSwitchIminsertToggleEcho = 0

It works for me. Notice that there is mapping <C-^> for switching Keymap assistance related keyboard layout in Normal mode. Note that dynamic assistance requires setting of g:XkbSwitchKeymapNames. I also checked the simple (static) config you showed, and it worked as well.

As to XkbSwitchAssistSKeymap, it is not actually working any more (and therefore is deprecated), because now search in the command line obeys the normal keyboard layout switching flow which unites the search mode with the Insert and Select modes.

mario-amazing commented 1 year ago

IMHO expected behaiviour the same as you described above. But when I press fg(with previous Russian language), vim tried to find g letter. I have tried your proposal with lua config, but have the same result:

-- vim-xkbswitch
vim.g.XkbSwitchLib = '/usr/local/bin/libxkbswitch.dylib'
vim.g.XkbSwitchEnabled = 1
vim.g.XkbSwitchIMappings = { 'ru' }
vim.g.XkbSwitchAssistNKeymap = 1    -- for commands r and f
vim.g.XkbSwitchDynamicKeymap = 1
vim.g.XkbSwitchKeymapNames = {['ru'] = 'russian-jcukenwin', ['uk'] = 'ukrainian-jcuken'}
vim.g.XkbSwitchIminsertToggleEcho = 0
lyokha commented 1 year ago

After you return from Insert mode with Russian layout to Normal mode, what command

:echo b:xkb_layout

says? Does it say ru?

mario-amazing commented 1 year ago

E121: Undefined variable: b:xkb_layout

lyokha commented 1 year ago

I made a typo, I meant b:xkb_ilayout

mario-amazing commented 1 year ago

:echo b:xkb_ilayout: 1 when English 3

lyokha commented 1 year ago

Values 1 and 3 are rather weird: they are keyboard layout names and therefore should normally be like us and ru. But if you really have such names, then use dynamic keymap assistance with

let g:XkbSwitchKeymapNames = {'1' : 'russian-jcukenwin'}
mario-amazing commented 1 year ago

Still the same behavior