hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
8.14k stars 405 forks source link

Weird behavior of SelectBehavior.Insert #2075

Closed MinhTran0911 closed 3 weeks ago

MinhTran0911 commented 3 weeks ago

This is my current mapping:

['<Tab>'] = cmp.mapping(function(fallback)
    if luasnip.locally_jumpable(1) then
        luasnip.jump(1)
    elseif cmp.visible() then
         if #cmp.get_entries() == 1 then
            cmp.confirm({ select = true })
         else
            cmp.select_next_item({ behavior = cmp.SelectBehavior.Insert })
         end
    elseif has_words_before() then
        cmp.complete()
        if #cmp.get_entries() == 1 then
            cmp.confirm({ select = true })
        end
    else
        fallback()
     end
end, {'i', 's'}),

My desired behavior is that when I select the entry with SelectBehavior.Insert, I can press \<Tab> to cycle through the entries for the current word. But the behavior I'm seeing is that when I select an entry, it is inserted and then the completion changes for the newly-inserted word. For example: Possible completions: "foo_bar", "foo_bar_baz" If I type "foo_b|" and \<Tab>, then "foo_bar" is inserted, and the completion menu changes to show "foo_bar_baz" only. If I \<Tab> 2nd time, then it becomes "foo_bar_baz". Now \<Tab> 3rd time will do nothing because there's no more completion.

I expect that if I \<Tab> the 3rd time it will cycle back to "foo_bar" (based on my originally typed "foo_b", not based on "foo_bar" that get inserted). Is there a way to achieve such behavior?

MinhTran0911 commented 3 weeks ago

It seems the there is some conflict with the vim-matchup plugin that prevent my desired behavior. I tried remove vim-matchup and that fixed my problem. Don't really know what's the conflict is exactly, but I'll close the issue for now.