neovide icon indicating copy to clipboard operation
neovide copied to clipboard

neovide ignores 'alt+' codes on Windows

Open fautore opened this issue 10 months ago • 6 comments

Describe the bug Neovide running on Windows ignores 'alt+' codes to paste unicode characters that are not present in standard keyboards.

To Reproduce

  1. Open a neovide in Windows on a writable buffer
  2. Go into insert mode
  3. press <alt> + <whathever number combination> (i tried alt+96 (`) and alt+126 (~))
  4. relase <alt>
  5. input ignored

Expected behavior The character should be inserted into the buffer after releasing

Desktop (please complete the following information):

  • OS: Windows 11
  • Neovide Version 0.11.2
  • Neovim Version 0.9.1

logs I can provide logs when running the steps to reproduce, if necessary

Additional context https://www.alt-codes.net/

fautore avatar Mar 28 '24 16:03 fautore

That's very tricky to implement, due to the fact that someone might want to map alt-0 for example to something, so we have to send the key to Neovim as soon as it happens.

But you can use this instead: https://neovim.io/doc/user/insert.html#i_CTRL-V_digit

If you type something often, you could also possibly use abbreviations: https://neovim.io/doc/user/usr_24.html#24.7

fredizzimo avatar Mar 28 '24 16:03 fredizzimo

I thought it possible to do that with a plugin, something like

function! s:AltMap(start)
    let nr = s:keys[a:start]
    let i = 0
    let extra = ""
    while 1
        let next = getchar(1)
        if next is# 0
            sleep 1m
            let i += 1
        elseif next is# 0x80
            " Note: getcharstr(1) for some reason only gets first byte which is 
            " 0x80. Thus may just as well use getchar() and not allocate 
            " a useless string.
            let s = getcharstr()
            if has_key(s:keys, s)
                let i = 0
                let nr = nr * 10 + s:keys[s]
            else
                break
            endif
        else
            break
        endif
    endwhile
    return nr2char(nr) . extra
endfunction

function! MakeMaps()
    unlockvar s:keys
    let s:keys = {}
    let v = 0
    let alts = ["Insert",
              \ "kEnd", "Down", "kPageDown",
              \ "Left", "kOrigin", "Right",
              \ "kHome", "Up", "kPageUp"]
    while v < 10
        for key in ["".v, alts[v]]
            let mkeyhrstr = "<M-" . key . ">"
            let mkeystr = eval('"\' . mkeyhrstr . '"')
            let s:keys[mkeystr] = v
            execute 'map <expr>' mkeyhrstr '<SID>AltMap('.string(mkeystr).')'
            execute 'map! <expr>' mkeyhrstr '<SID>AltMap('.string(mkeystr).')'
        endfor
        let v += 1
    endwhile
    lockvar! s:keys
endfunction

call MakeMaps()

After checking that I still think it is possible, but unfortunately, this specific code tends to fail due to getcharstr() often returning incomplete strings for some reason. One should be able to fix the issue with more complicated logic (something like “if s is a prefix of any key in s:keys use getcharstr() again, concatenate outputs and retry with that”), but I am not up to writing that now.

In any case, you can do this with a plugin, only if you are OK with character appearing either after timeout or after typing something else instead of after Alt release. Also plugin could not care whether or not you released Alt button while typing Alt+number sequence: button release events are not forwarded to neovim.

ZyX-II avatar Mar 28 '24 21:03 ZyX-II

I am wondering though: if it is a common convention, should not there be either some option used on window creation (i.e. implemented by Windows itself) or, at least, winit option to not forward Alt+number events until release of Alt with neovide merely enabling/disabling it with some configuration option (at the cost of <A-N> mappings in this case)?

ZyX-II avatar Mar 28 '24 21:03 ZyX-II

I have the same problem on OSX

D00mch avatar Jul 05 '24 18:07 D00mch

Can also confirm this same issue on osx. My hacky workaround is to remap the option maps I'm used to to something else (eg. ctrl+shift+f16) in karabiner for neovide gui

svermeulen avatar Sep 03 '24 06:09 svermeulen

@svermeulen there is a better workaound. Just focus any text editor window and type alt+q — you will have this œ. The same works with other <alt+character>. And you can map it as is:

"alt+shift+.   <M-S-.>
nnoremap ˘ <C-w>5+
"alt+shift+,   <M-S-,>
nnoremap ¯ <C-w>5-
"alt+.   <M-.>
nnoremap ≥ <C-w>5>
"alt+,   <M-,>
nnoremap ≤ <C-w>5<

D00mch avatar Sep 03 '24 09:09 D00mch