Closed Thanatermesis closed 1 year ago
It seems dup of https://github.com/hrsh7th/nvim-cmp/discussions/1424
Sorry. I can't understand.
I guess you should check the following two points.
The preselect
option
See :help cmp-faq
Remove completeopt
setting and set coompleteopt
as vim option
set completeopt=menu,menuone,noselect
@hrsh7th tried but doesn't seems to work, I have recorded a video showing the issue: https://youtu.be/awc4BjLwf9M
What do you get the result with the followings?
:echomsg &completeopt
:imap <Tab>
:lua= require('cmp').get_config()
It seems Vim completeopt menu behavior(manual completion). nvim-cmp default behavior is for auto completion.
menu,preview
i
@Thanatermesis Could you try with :set completeopt=menu,menuone,noselect
?
I can't determine the root cause. Sorry.
@Thanatermesis You should create the minimal init.lua
for it.
Is nvim-cmp updated to the latest version?
Also, please provide a stand alone init.lua
that describes the minimal configuration necessary to reproduce this issue as @Shougo suggests. This is a good base to build on.
@Thanatermesis Could you try with
:set completeopt=menu,menuone,noselect
?
Same issue, pressed Tab and the menu appears but my text is not replaced with the first result 🤔
Is nvim-cmp updated to the latest version?
Yes, I'm using the NvChad framework which already included nvim-cmp integrated, so maybe this can be an easy way to reproduce it (in a test environment, install NvChad in a single command, everything goes installed and nvim-cmp included, then change the trigger like "autocomplete = false" and add Tab to open the menu, just like in the video, and the bug should happen)
Please don't use the plugin distribution for it. It is not easy to reproduce for us.
Could you try the following?
require('cmp').setup {
completion = {
completeopt = 'menu,menuone,noselect'
}
}
My nvim-cmp config does not reproduce this problem so I think you should raise issue for the nvchad side.
There's a small screencast of all the process (installing the nvim NvChad framework from zero, and without extra plugins) from scratch, the modifications I did to disable the autopopup, and showing the issue, including a "set" of the parameters you told me, in a strange way even if I set the values you said, it seems like when running nvim they are replaced by "menu,preview" 🤔
My nvim-cmp config does not reproduce this problem so I think you should raise issue for the nvchad side.
Maybe @siduck knows why the value of completeopt is replaced
Note: the bug is on the minute 5:00, already included on the link:
There's a small screencast of all the process (installing the nvim NvChad framework from zero, and without extra plugins) from scratch, the modifications I did to disable the autopopup, and showing the issue, including a "set" of the parameters you told me, in a strange way even if I set the values you said, it seems like when running nvim they are replaced by "menu,preview" thinking
My nvim-cmp config does not reproduce this problem so I think you should raise issue for the nvchad side.
Maybe @siduck knows why the value of completeopt is replaced
Note: the bug is on the minute 5:00, already included on the link:
just override nvim-cmp opts in your custom plugins
@siduck yes that's what I do but it doesn't seems to take effect, I changed it to "menu,menuone,noselect" but it doesn't gets static (as you can see in the video), on the other hand I set it manually with :set to that value but the bug stills present 🤔
works here tho
@Thanatermesis
{
"hrsh7th/nvim-cmp",
opts = {
completion = {
completeopt = "menu,menuone,noselect",
},
},
},
@siduck Mmmh, I don't think so, the issue is that when the menu is set to not automatically popup all the time but with manually triggering it, so by pressing tab, the text is not autocompleted to the first result, only to the next ones
This means, adding "autocomplete = false," on the completion section, and in the TAB mapping, changing the fallback line to "cmp.complete()"
More details on the first post and a demo on the video: https://youtu.be/awc4BjLwf9M
Ok so I think this code made it finally working, so first I need to have the entry to completeopt = "menu,menuone,noselect",
otherwise without "noselect", the first selection will be made (without filling up my code with it, so what is this issue about),
Then, I need to replace the cmp.complete()
entry (which is triggered with Tab) using this combination instead, which If im not wrong what it does is "create the menu" and "switch to the first item"
cmp.complete({ behavior = cmp.SelectBehavior.Select })
cmp.select_next_item({ behavior = cmp.SelectBehavior.Insert })
This looks very good! the menu only appears when I press Tab, at the same time my text has the added keyword, if I press "space" the keyword is kept (used) on my line, if i want to open a snippet I press "enter"... same behaviour with the menu automatically showing up (which is annoying for me at the moment because it doesn't lets me to use Copilot as I mentioned here)
For anyone coming across this from google, you can improve it a little bit more by conditionally running complete based on whether the menu is already open. heres the full example I'm using right now:
["<C-k>"] = cmp.mapping(function(fallback)
if not cmp.visible() then
cmp.complete({ behavior = cmp.SelectBehavior.Select })
end
cmp.select_prev_item({ behavior = cmp.SelectBehavior.Insert })
end, { 'i', 's' }),
["<C-j>"] = cmp.mapping(function(fallback)
if not cmp.visible() then
cmp.complete({ behavior = cmp.SelectBehavior.Select })
end
cmp.select_next_item({ behavior = cmp.SelectBehavior.Insert })
end, { 'i', 's' }),
I have the "autocomplete = false", so menu only opens when I hit "tab"
If you see, when the second item is selected, the text in the cursor is filled up (similar to ghost_text), but this doesn't happens with the first item
In the normal behaviour that's somewhat normal, where the menu always opens with the first item preselected, but only when you scroll to the next option your cursor's text is modified, the issue is that the first item is not really preselected just hilighted, but when you trigger cmp.complete(), the first item should be selected in the same way the next ones are