Search code examples
neovim

make nvim-cmp not autoselect the 1st option


I'm using nvim-cmp as my completion engine, which is working fine, but would like to change the default behavior to disable the automatic selection of the first option. The reason is that, when the last word of a line has suggestions, pressing enter will apply the first suggestion instead of just inserting a newline.

For example, in haskell, typing

main = do<CR>

the do matches diso~ from luasnip, and is replaced by something like

main = 2022-12-05T12:50:34

I would prefer the suggestions to be visible but none of them selected until tab is pressed, and if none is selected then <CR> is just a newline. Is this possible?


Solution

  • Answering my own question, I found out that when using lsp-zero, the configuration has to be done there. The documention in advanced-usage.md provides the exact solution, which I'm posting here:

    local lsp = require('lsp-zero')
    lsp.preset('system-lsp')  -- or recommended, or whatever...
    lsp.setup_nvim_cmp({
        preselect = 'none',
        completion = {
            completeopt = 'menu,menuone,noinsert,noselect'
        },
    })
    lsp.setup()