codeium.vim icon indicating copy to clipboard operation
codeium.vim copied to clipboard

Next suggestion key binding not working

Open LidorAbo opened this issue 1 year ago • 2 comments

I running the following vim:

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled May 10 2022 08:40:37)
Included patches: 1-749

in the following OS:

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.4 LTS
Release:	22.04
Codename:	jammy

But the default keybinding(<M-]>) for codeium next suggestion not working when i press left Alt key + [ key in the keyboard(see attched video).

But when i tried to set <M-[> to relevant escape characters the keybinding working as expected but the behaviour is very strange(see attached screenshot below).

How i can solve it?

Thanks Screenshot from 2024-04-09 15-10-12 Screenshot from 2024-04-09 15-20-18

Screencast from 09-04-24 15:23:07.webm

LidorAbo avatar Apr 09 '24 14:04 LidorAbo

Wasn't working for me. I was able to do this instead, though:

" codeium
imap <S-Tab> <Cmd>call codeium#CycleCompletions(1)<CR>
set statusline+=\{…\}%3{codeium#GetStatusString()}

This makes Shift + Tab the next suggestion. Single Tab remains accept as per defaults. No combination of Ctrl + key worked.

gxespino avatar Aug 31 '24 21:08 gxespino

Here is an excerpt from vim doc:

1.10 MAPPING ALT-KEYS                                   :map-alt-keys 

...

In the GUI Vim handles the Alt key itself, thus mapping keys with ALT should
always work.  But in a terminal Vim gets a sequence of bytes and has to figure
out whether ALT was pressed or not.

...

By default Vim assumes that pressing the ALT key sets the 8th bit of a typed
character.  Most decent terminals can work that way, such as xterm, aterm and
rxvt.  If your <A-k> mappings don't work it might be that the terminal is
prefixing the character with an ESC character.  But you can just as well type
ESC before a character, thus Vim doesn't know what happened (except for
checking the delay between characters, which is not reliable).

As of this writing, some mainstream terminals like gnome-terminal and konsole
use the ESC prefix.  There doesn't appear a way to have them use the 8th bit
instead.  Xterm should work well by default.  Aterm and rxvt should work well
when started with the "--meta8" argument.  You can also tweak resources like
"metaSendsEscape", "eightBitInput" and "eightBitOutput".

which clearly states that it's not possible to make vim in gnome-terminal to recognize <M-]>, <M-[> and <M-\>. As an example one could bind mappings to <ESC>... key sequence. It's kinda work, but breaks a lot of other things instead:

" DON'T DO THIS
imap <ESC>] <Plug>(codeium-next-or-complete)
imap <ESC>[ <Plug>(codeium-previous)
imap <ESC>\ <Plug>(codeium-complete)

Same time ALT with keys from arrows and editing blocks works. I.e. I personally ended up with following configuration:

function! g:CodeiumUncycleOrComplete() abort
  if !exists('b:_codeium_completions')
    call codeium#Complete()
  else
    call codeium#CycleCompletions(-1)
  endif
endfunction

let g:codeium_disable_bindings = 1
let g:codeium_manual = v:true

function! CodeiumKeys()
  imap <M-PageDown> <Cmd>call codeium#CycleOrComplete()<CR>
  imap <M-PageUp> <Cmd>call g:CodeiumUncycleorComplete()<CR>

  imap <script><silent><nowait><expr> <M-Delete> codeium#Clear()
  imap <script><silent><nowait><expr> <M-End> codeium#Accept()

  imap <script><silent><nowait><expr> <M-Insert> codeium#AcceptNextWord()
  imap <script><silent><nowait><expr> <M-Home> codeium#AcceptNextLine()
endfunction

call CodeiumKeys()

RomanValov avatar Feb 24 '25 22:02 RomanValov