-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to trigger autocomplete on InsertEnter only for a single source (e.g., Copilot)? #1197
Comments
Something like that:
|
Thank for the suggestion @fnix2! However, this is not working for me. For example, when I write a comment (which Copilot uses to generate completion suggestions) and I start a new line below, the completion is not triggered. If I then write a letter, then the completion is triggered for all completion sources; if next, I remove that letter and have an empty line again, then only Copilot suggestions are shown. Hence, I have some indication that setting Here are some relevant parts of my config: completion = {
autocomplete = {
cmp.TriggerEvent.TextChanged,
cmp.TriggerEvent.InsertEnter,
},
completeopt = "menuone,noinsert,noselect",
keyword_length = 1,
} sources = {
{ name = "copilot", keyword_length = 0 },
{ name = "luasnip" },
{ name = "nvim_lsp" },
{ name = "buffer" },
{ name = "path" },
{ name = "dap" },
}, I suppose this is not working as intended? |
Hm... It is reproduced for me. I don't know why. |
If you only want to enable single source and perform completion in InsertEnter , you'll have to do it yourself. nvim-cmp does not implement features for all special situations. Instead, it provides an API. And nvim-cmp does not support keyword_length=0 now. PR welcome. autocmd InsertEnter * call s:on_insert_enter()
function! s:on_insert_enter()
lua <<EOF
vim.schedule(function()
local cmp = require('cmp')
cmp.complete({
config = {
sources = {
{ name = 'buffer' }
}
}
})
end)
EOF
endfunction |
I'm jealous, this is just the behaviour that I'm looking for, but can't seem to achieve even after lots of searching. What I'd like is for cmp to only autocomplete after I start typing the first character, and not immediately upon creating a new line. It would seem that all I need to do is to include the following:
Right now, everything works great with one exception: if I create a new line, then the autocomplete menu opens even before I start typing. This only happens if I'm inside a function like |
@benbrastmckie is this black magic? I have the same configuration as you mention, yet my problem is the opposite: it does not trigger on new lines. Would you mind sharing your complete cmp config to compare? |
Sure thing. Would love any thoughts if you can places to make improvements.
I also came across some code that I haven't got to work yet:
Hope that helps! |
I am trying to use Copilot with
nvim-cmp
and my current problem is that, after writing a comment suggesting what I want Copilot to do, I still have to enter a new line and write at least one character to trigger thenvim-cmp
autocompletion engine which allows me to autocomplete with Copilot.To solve this, I have attempted to use this bit of config:
However, this triggers autocompletion on
InsertEnter
for all sources, so it is quite annoying. Is there any way to only trigger on theInsertEnter
event when Copilot has suggestions?Thanks!
The text was updated successfully, but these errors were encountered: