Exafunction / codeium.vim

Free, ultrafast Copilot alternative for Vim and Neovim
https://codeium.com
MIT License
4.3k stars 157 forks source link

How to change keymap for #Accept? #142

Closed vinoff closed 1 year ago

vinoff commented 1 year ago

For Copilot, I have the following keymap:

imap <silent><script><expr> <Right> copilot#Accept("<Right>")

How would I translate that for Codeium? I tried changing "copilot" for "codeium", as shown below, but it does not work..

imap <silent><script><expr> <Right> codeium#Accept("<Right>")

Any help would be appreciated. I want to use the Right arrow key as keymap for accepting the suggestion..

nyngwang commented 1 year ago

Maybe you just need to remove the argument "<Right>" from the call, as per README.

vinoff commented 1 year ago

Doing:

imap <silent><script><expr> <Right> codeium#Accept()

sorta works, but now the right arrow doesn't behave as expected when there is no codeium suggestions...

nyngwang commented 1 year ago

I'm not familiar with Vim Script, so I cannot help you further If you want to have a multiplex <Right>. If Codeium.vim might provide an api to let you know if any suggestion is visible, then I believe what you're saying can be easily achieved.

As a workaround, I will recommend you using another keymap instead.

Shougo commented 1 year ago

I think you can use exists('b:_codeium_completions').

inoremap <silent><expr> <Right> exists('b:_codeium_completions') ? codeium#Accept() : "\<Right>"
nyngwang commented 1 year ago

@Shougo Hi, is it possible to translate the code into Lua? Specifically, I would like to know how to access the buffer variable b:_codeium_completions in Lua from Neovim. This could help me too, #124.

update: Nevermind, I just found that it can be accessed via vim.b.. I guess the API you added in #137 is for this?

Shougo commented 1 year ago

I guess the API you added in https://github.com/Exafunction/codeium.vim/pull/137 is for this?

It is not related. I have added the API for my completion plugin.

vinoff commented 1 year ago

inoremap exists('b:_codeium_completions') ? codeium#Accept() : "\"

Thank you, but sadly this does not work. When I press right (in insert mode), it seems to add a tab (4 spaces)...

Shougo commented 1 year ago

Hm...

It works for me.

  inoremap <silent><expr> <Right>
  \ exists('b:_codeium_completions') && !empty(get(b:_codeium_completions, 'items', [])) ?
  \ codeium#Accept() : "\<Right>"
vinoff commented 1 year ago
 inoremap <silent><expr> <Right>
  \ exists('b:_codeium_completions') && !empty(get(b:_codeium_completions, 'items', [])) ?
  \ codeium#Accept() : "\<Right>"

Yes, this works as expected! Thank you Shougo!!

LichKing-W commented 10 months ago
 inoremap <silent><expr> <Right>
  \ exists('b:_codeium_completions') && !empty(get(b:_codeium_completions, 'items', [])) ?
  \ codeium#Accept() : "\<Right>"

i'm not familiar with vim and lua. does anyone know how can i config this in lua?