Thank you for your interest in this rather specialized question.
This is a follow-up to this question : Mapping for expression register with langmap active
I’m looking for the best way to associate two different keymaps in (Neo)vim, one to input text (bépo in my case) and US Qwerty for all the other commands.
1- When using langmap, is it possible to replay the same characters as recorded by the macro instead of the same keys ?
2- Alternatively, when using keymap, is it possible on Arch Linux, ST terminal and Neovim to map chords such as CTRL + ALT + A (more specifically AltGr / right Alt) when using a qwerty layout ?
3- If nothing else, could a macro enable transparent switching between OS keymap upon entering and exiting insert / find mode ?
I have learnt VIM by using the game VIM adventures, this made me use the US layout for normal commands which seemed a reasonnable choice, albeit a bit daunting at first as I needed to switch mentally between two layouts for inputting text to qwerty for the commands.
I could actually get used to it, but configuring (neo)vim has never been fully satisfying as I am encountering limitations while improving my vim-fu.
My journey so far:
- Solution 1 : remap every character combination, using noremap, nnoremap etc.
- advantages : the mappings are generally simple to implement
- disadvantages :
- really tedious to maintain and expand when learning new commands
- does not display the intended key in the status line triggered by the showcmd option
- Solution 2 : langmap.
- much easier to maintain, as simple correspondance list is required
- displays the intended command key in the status line (translation is done by Vim)
by configuring some remap just for insert mode, I could keep the same behavior for insert mode and make shortcuts such as ctrl + W delete the word backward for instance.
- For now, I mostly use command line mode for substitution so inputting commands in fr layout is not disturbing as I input words rather than commands.
- Macros are recorded with qwerty like-layout, but replays with my locale layout, ie fr-bepo. That make them unusable.
Solution 3 : keymap
- With keymap, the OS keymap is set to Qwerty, so the responsability to change on locale keymap rests upon Vim when entering Insert and Search modes, and Vim is in charge of translating the keypresses from QWERTY to the target locale keymap.
From what I could test, this is perfect as every normal mode command is of course using the US layout natively and I really wish this could work BUT…
- My locale keymap makes a really heavy use of the CTRL + ALT (aka AltGr) modifier which is also combined with SHIFT (Shift + AltGr). From what I’ve read, it is not possible to use this chording in Vim but may work with certain terminals in Neovim. I could not find my way through this, does anybody have succeded make this work ? I use Arch, btw 😉 and ST as Terminal.
- Solution 4 : automatically switch OS keymap for normal mode
- This could be the most simple solution, and the one I should have used before it seems.
:!setxkbmap us works well, but I could not yet find from the help the autocmd function that would enable this workflow :
- upon starting Vim: switch to Qwerty layout
- normal mode, search character (triggered by f/F/t/T): switch to fr-bepo layout
exit search: back to Qwerty
enters insert mode: fr-bepo
back to normal mode : Qwerty
exit Vim : back to fr-bepo
Thanks a lot for your reading !