Search code examples
code-snippetsneovim

How can I limit the neovim's autocomplete options to only snippets?


I'm running neovim 0.7 with LuaSnips to develop in Flutter.

I've installed a couple of Flutter snippets libraries, which work OK.

The problem I'm experiencing is that my autocomplete dropdown contains many many lsp suggestions which obscure the snippets. For example, typing provider gives me 30 or so lsp derived suggestions before I get to the snippets at the very bottom.

Is there any way I can either prioritise snippets to the top of the list, or use an alternate autocomple key that only offers snippets?

:CmpStatus gives me

# ready source names                                                                                                                                                                                                                                                                                                         
- buffer                                                                                                                                                                                                                                                                                                                     
- luasnip                                                                                                                                                                                                                                                                                                                    
- path                                                                                                                                                                                                                                                                                                                       
- nvim_lsp:dartls  

Solution

  • In your nvim-cmp plugin configuration, the order of the sources determines their order in the completion results.

    You could also set priority for each source with priority option. If you want to prioritize snippets with luasnip, set the highest priority for it :

    sources = {
      { name = 'luasnip', priority = 40 },
      { name = 'nvim_lsp', priority = 30 },
      { name = 'buffer', priority = 20 },
      { name = 'path', priority = 10 },
    },