Closed chrisgrieser closed 1 year ago
I'm using Lunarvim and for me it is the other way around. I only insert tabs and can't accept the suggestion.
I'm using Lunarvim and for me it is the other way around. I only insert tabs and can't accept the suggestion.
I have same issue, the suggestion is diplayed, but pressing Tab
does not complete the file
I updated Lunarvim to its latest version and now it works. \o/
Be sure the same config below is added to your config (be sure it's the same - if you're using packer or you can modify if you're using lazy)
use {
'Exafunction/codeium.vim',
config = function ()
-- Change '<C-g>' here to any keycode you like.
vim.keymap.set('i', '<C-g>', function ()
return vim.fn['codeium#Accept']()
end, { expr = true })
end
}
So C-g
will do the suggestion completion. you can change it of course.
the
That's what solved the problem for me.
okay, for whatever weird reason, I just installed codium on a different device, with 100% the same config and this issue does not occur on this device, everything seems to work fine.
For those who use cmp
, I was able to make it work by adding the following Lua configuration :
local cmp = require('cmp')
cmp.setup {
mapping = {
['<Tab>'] = cmp.mapping((function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
vim.fn['codeium#Accept']()
fallback()
end
end), {'i', 's'})
}
}
It looks like everyone in this thread has had their issue resolved, so I'll close it. @mikaoelitiana do you think your snippet would be helpful for others? If so feel free to add a PR for the README.
For those who use
cmp
, I was able to make it work by adding the following Lua configuration :local cmp = require('cmp') cmp.setup { mapping = { ['<Tab>'] = cmp.mapping((function(fallback) if cmp.visible() then cmp.select_next_item() else vim.fn['codeium#Accept']() fallback() end end), {'i', 's'}) } }
I actually cannot seem to get codium#Accept function to work within nvim-cmp. I also tried to entirely copy this config, with no results.
The function gets executed, but nothing is inserted in the buffer.
If I print the function return value I get ^O:call cursor(3,1)^M^Od3l^R^O=codeium#CompletionText()^M
For those who use
cmp
, I was able to make it work by adding the following Lua configuration :local cmp = require('cmp') cmp.setup { mapping = { ['<Tab>'] = cmp.mapping((function(fallback) if cmp.visible() then cmp.select_next_item() else vim.fn['codeium#Accept']() fallback() end end), {'i', 's'}) } }
I actually cannot seem to get codium#Accept function to work within nvim-cmp. I also tried to entirely copy this config, with no results.
The function gets executed, but nothing is inserted in the buffer.
If I print the function return value I get
^O:call cursor(3,1)^M^Od3l^R^O=codeium#CompletionText()^M
Have you able to solved the problem?
I have been able to solve that. The problem with that solution is that the keymaps for this plugin have expr = true
, meaning that vim.fn['codeium#Accept']()
does not execute the insertion, but rather returns a string which represents the execution.
I solved it by just mapping this:
vim.keymap.set("i", "<Tab>", function() return vim.fn["codeium#Accept"]() end,{ expr = true, silent = true })
and using this in my cmp config. when cmp is not visible, it will use the fallback function, which is the <tab>
mapping above.
local cmp = require('cmp')
cmp.setup {
mapping = {
['<Tab>'] = cmp.mapping((function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end), {'i', 's'})
}
}
It's not a perfect solution, but a cleaner solution would require the codeium devs to offer some more flexible plugin methods for the user.
Thanks for your solution, however, I tried yours but still couldn't make it to work
I'm using LazyVIM and here is my cmp
local luasnip = require("luasnip")
local cmp = require("cmp")
opts.mapping = vim.tbl_extend("force", opts.mapping, {
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
-- You could replace select_next_item() with confirm({ select = true }) to get VS Code autocompletion behavior
cmp.select_next_item()
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
-- this way you will only jump inside the snippet region
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
})
And Codeium
return {
{
"Exafunction/codeium.vim",
enabled = true,
-- stylua: ignore
config = function()
vim.g.codeium_idle_delay = 75
vim.g.codeium_disable_bindings = 1
vim.keymap.set("i", "<Tab>", function() return vim.fn["codeium#Accept"]() end,{ expr = true, silent = true })
-- vim.keymap.set("i", "<A-g>", function() return vim.fn["codeium#Accept"]() end, { expr = true })
-- vim.keymap.set("i", "<A-f>", function() return vim.fn["codeium#CycleCompletions"](1) end, { expr = true })
-- vim.keymap.set("i", "<A-b>", function() return vim.fn["codeium#CycleCompletions"](-1) end, { expr = true })
-- vim.keymap.set("i", "<A-e>", function() return vim.fn["codeium#Clear"]() end, { expr = true })
-- vim.keymap.set("i", "<A-s>", function() return vim.fn["codeium#Complete"]() end, { expr = true })
end,
},
}
@hoangvu12 probably it's elseif has_words_before()
becomes true most of the time and therefore prevents fallback()
to ever be reached.
@hoangvu12 probably it's
elseif has_words_before()
becomes true most of the time and therefore preventsfallback()
to ever be reached.
I commented it out and still didn't work. When I pressed tab, it indent instead of accept codeium
when the plugin is enabled, it becomes impossible to insert a tab.