Exafunction / codeium.vim

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

Can't accept suggestion #215

Open jjohnston-aims opened 1 year ago

jjohnston-aims commented 1 year ago

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 commented 1 year ago

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

jjohnston-aims commented 1 year ago

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

Jendker commented 1 year ago

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.

Zak9O commented 12 months ago

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
    },
jakubbortlik commented 11 months ago

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 commented 11 months ago

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.

eerii commented 11 months ago

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), "")
jakubbortlik commented 11 months ago

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.

AnoRebel commented 10 months ago

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

josephcrawfordSRH commented 6 months ago

I am having a similar issue. In insert mode if i hit 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 :/

aemonge commented 5 months ago

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 commented 5 months ago

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
}
zx0r commented 1 week ago

-- The configuration below provides a robust setup with custom keybindings that work perfectly with Codeium
-- Codeium: AI-powered code completion and suggestions
return {
  "Exafunction/codeium.nvim",
  event = "BufEnter",
  dependencies = {
    "nvim-lua/plenary.nvim",
    "hrsh7th/nvim-cmp",
    -- "lspkind.nvim", -- Added missing dependency
  },
  config = function()
    -- Disable default bindings
    vim.g.codeium_disable_bindings = 1

    -- Custom keymaps table
    local keymaps = {
      accept = {
        mode = "i",
        lhs = "<M-a>",
        rhs = function()
          return vim.fn["codeium#Accept"]()
        end,
        opts = { silent = true, expr = true },
      },
      next = {
        mode = "i",
        lhs = "<M-]>",
        rhs = function()
          return vim.fn["codeium#CycleCompletions"](1)
        end,
        opts = { expr = true },
      },
      prev = {
        mode = "i",
        lhs = "<M-[>",
        rhs = function()
          return vim.fn["codeium#CycleCompletions"](-1)
        end,
        opts = { expr = true },
      },
      clear = {
        mode = "i",
        lhs = "<Esc>",
        rhs = function()
          return vim.fn["codeium#Clear"]()
        end,
        opts = { expr = true },
      },
    }

    -- Apply keymaps
    for _, mapping in pairs(keymaps) do
      vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts)
    end

    require("codeium").setup({
    })
   end,
}
bnystrom commented 1 week ago

Hate to say "Same Issue here", but even after a year only @eerii workaround works for me without trying to locate what other plugin collides and causes this issue. I know that without the workaround, "Accept" works, but only with minimal plugins loaded. (NeoVim / LazyVim)