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

Can't accept suggestion

Open jjohnston-aims opened this issue 2 years ago • 15 comments

I am trying to use the right arrow to accept a codeium suggestion:

  {
  'Exafunction/codeium.vim',
  config = function ()
    vim.keymap.set('i', '<Right>', function () return vim.fn['codeium#Accept']() end, { expr = true })
  end
  },

It accepts the suggestion ok, but when I am in the middle of a word and press <Right> it inserts a <Tab>.

Edit: fix formatting in last line

jjohnston-aims avatar Aug 29 '23 23:08 jjohnston-aims

I think there is a conflict with nvim-cmp. I am using LazyVim

jjohnston-aims avatar Sep 11 '23 22:09 jjohnston-aims

I disabled nvim-cmp and cmp-nvim-lsp, but the issue persists.

jjohnston-aims avatar Sep 11 '23 23:09 jjohnston-aims

Similar issue here. It works with:

vim.keymap.set('i', '<a-a>', function () return vim.fn['codeium#Accept']() end, { expr = true, silent = true, desc = "Codeium accept"})

but doesn't work with another binding:

local cmp_mappings = {
  ['<Tab>'] = cmp.mapping(
    function(fallback)
        return vim.fn['codeium#Accept']()
    end, {"i","s"}),
}
cmp.setup({
  mapping = cmp_mappings
})

The function is executed in second case but the text is not inserted.

jborbik avatar Sep 21 '23 09:09 jborbik

Similar issue here. Keybinding to codeium#Accept does not work whereas codeium#CycleCompletions(1) works. I tried swapping the keybinds of the two commands anticipating the Accept function would start working and the CycleCompletions would break but no. CycleCompletions worked with the new keybinding and codeium#Accept still did not work.

I am using NVChad base configuration

Keybindings:

    ["<C-a>"] = { -- Does not work
      function()
        return vim.fn['codeium#Accept']()
      end,
      "Codeium Accept",
      expr = true
    },
    ["<C-s>"] = {
      function()
        return vim.fn['codeium#CycleCompletions'](1)
      end,
      "Codeium Accept",
      expr = true
    },

Zak9O avatar Nov 22 '23 20:11 Zak9O

I'm experiencing probably the same problem, I have this in my config: vim.keymap.set('i', '<M-p>', function () return vim.fn['codeium#Accept']() end, { expr = true }) and when I inspect the mapping with vim.api.nvim_get_keymap("i") after the plugin is loaded I see that the rhs of the mapping is nil. When, however, I run the vim.keymap.set command manually, the mapping is created correctly and <M-p> accepts suggestions.

jakubbortlik avatar Nov 28 '23 16:11 jakubbortlik

I'm experiencing probably the same problem, I have this in my config: vim.keymap.set('i', '<M-p>', function () return vim.fn['codeium#Accept']() end, { expr = true }) and when I inspect the mapping with vim.api.nvim_get_keymap("i") after the plugin is loaded I see that the rhs of the mapping is nil. When, however, I run the vim.keymap.set command manually, the mapping is created correctly and <M-p> accepts suggestions.

So apparently, rhs being nil is normal for keymaps created with {expr = true}. I've created a minimal init.lua with just lazy.nvim and codeium.vim and with it <M-p> mapping for codeium#Accept works as expected. So there probably is some interaction with some other plugin or setting that I have. I'll probably try bisecting my config to figure out what is causing the issue.

jakubbortlik avatar Nov 29 '23 08:11 jakubbortlik

This is an issue for me too. In the meantime, there's a hacky workaround using feedkeys (replace vim.fn[...]() with it):

vim.fn.feedkeys(vim.api.nvim_replace_termcodes(vim.fn["codeium#Accept"](), true, true, true), "")

eerii avatar Dec 15 '23 17:12 eerii

In my case the problem was that the <M-p> mapping was overridden by the vim-rsi plugin. I've replaced it with a different readline plugin that suits my needs even better and now I can use <M-p> for accepting completions without any problems.

jakubbortlik avatar Dec 18 '23 13:12 jakubbortlik

Any update of a possible fix for this apart from the workarounds? I have alot of plugins and little time to disable each one to find which one is messing with the codeium#Accept mapping. So far, @eerii's fix works for me, but i'd like the completion to be abit more seemless/natural(for lack of a better word) because there's a bit of a flash using the vim.fn.feedkeys method

AnoRebel avatar Jan 10 '24 13:01 AnoRebel

I am having a similar issue. In insert mode if i hit <Tab> it just inserts tabs and does not accept the suggestion, I am using LazyVim. None of the work-arounds above worked for me, I guess it is back to copilot in the meantime as that just works :/

josephcrawfordSRH avatar Apr 26 '24 13:04 josephcrawfordSRH

Same here with this config:

{
    'Exafunction/codeium.vim',
    keys = {
        { '<C-a>', '<Cmd>call codeium#CycleCompletions(1)<CR>', { noremap = true, silent = true, expr = true }, mode = "i" },
        { '<C-A>', '<Cmd>call codeium#CycleCompletions(-1)<CR>', { noremap = true, silent = true, expr = true }, mode = "i" },
        { '<C-l>', '<Cmd>call codeium#Accept()<CR>', { noremap = true, silent = true, expr = true }, mode = "i" },
        { '<leader>c', '<Cmd>call codeium#Chat()<CR>', { noremap = true, silent = true }, mode = "n", desc = "  Chat with Codeium" },
    },
    config = function()
        vim.g.codeium_disable_bindings = true
        vim.g.codeium_no_map_tab = true
        vim.g.codeium_enabled = true
    end
}

Also, I dont want the .nvim version, since I use coc.nvim as a completor engine, and I want the bot to be separeted from pyright suggestions and so.

aemonge avatar Jun 03 '24 08:06 aemonge

This is now working :rocket:

local M = {
    'Exafunction/codeium.vim',
    config = function()
        -- Change '<C-g>' here to any keycode you like.
        vim.keymap.set('i', '<C-l>', function() return vim.fn['codeium#Accept']() end, { expr = true, silent = true })
        vim.keymap.set('i', '<c-a>', function() return vim.fn['codeium#CycleCompletions'](1) end,
            { expr = true, silent = true })
        vim.keymap.set('i', '<c-z>', function() return vim.fn['codeium#CycleCompletions'](-1) end,
            { expr = true, silent = true })
        vim.keymap.set('i', '<c-x>', function() return vim.fn['codeium#Clear']() end, { expr = true, silent = true })
    end
}

aemonge avatar Jun 04 '24 08:06 aemonge