I have the following code in my vimrc:
function! s:WordPos(dir) abort return a:dir ==# 'right' \ ? searchpos('\<', 'nz', line('.')) \ : searchpos('\<', 'bn', line('.')) endfunction silent! execute "set <M-b>=\eb" silent! execute "set <M-f>=\ef" inoremap <expr> <M-b> <SID>WordPos('left') == 0 \ ? '<S-Left>' \ : repeat('<C-G>U<Left>', col('.') - <SID>WordPos('left')) inoremap <expr> <M-f> <SID>WordPos('right') == 0 \ ? '<S-Right>' \ : repeat('<C-G>U<Right>', <SID>WordPos('right') - col('.'))
The goal is to move by words in insert mode with
Alt-f without breaking the undo sequence.
It works more or less but if I try to type the character
â, instead of inserting it, Vim triggers the mapping for
Alt-b, which makes the cursor move one word backward.
As soon as I comment the mapping for
Alt-b, the problem disappears.
It happens in Vim as well as in gVim.
The output of the shell command
xxd -p when I hit
1b62, and for
Why does Vim interpret
Alt-b even though the keycodes seem different?