Skip to content

completeopt without noselect does not expand the auto-selected first entry #1136

Description

@dansalvato

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Announcement

Minimal reproducible full config

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'dcampos/nvim-snippy'
Plug 'dcampos/cmp-snippy'
Plug 'neovim/nvim-lspconfig'
call plug#end()
PlugInstall | quit

" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require'cmp'

cmp.setup({
  snippet = {
    expand = function(args)
      require('snippy').expand_snippet(args.body)
    end,
  },
  completion = {
    autocomplete = false,
    completeopt = 'menu,menuone'
  },
  window = {
    completion = cmp.config.window.bordered({ border = 'single' }),
    documentation = cmp.config.window.bordered({ border = 'single' }),
  },
  mapping = cmp.mapping.preset.insert({
    ['<C-d>'] = cmp.mapping.scroll_docs(-4),
    ['<C-u>'] = cmp.mapping.scroll_docs(4),
    ['<C-e>'] = cmp.mapping.abort(),
    ['<C-y>'] = cmp.mapping.confirm({ select = true }),
  }),
  sources = cmp.config.sources({
    { name = 'nvim_lsp' },
    { name = 'snippy' }, -- For snippy users.
  }, {
    { name = 'buffer' },
  }),
  -- preselect = cmp.PreselectMode.Item,
})

cmp.setup({
  mapping = {
    ['<C-n>'] = function(_)
      if not cmp.visible() then
        cmp.complete()
      else
        cmp.select_next_item()
      end
    end,
  }
})
EOF

lua << EOF
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())

require'lspconfig'.cssls.setup {
  capabilities = capabilities,
}
EOF

Description

I am trying to mimic the default Vim completion menu, in which pressing <C-n> will open the menu and select and expand the first entry. So, I set cmp's completeopt to menu,menuone. The first entry does indeed get selected on cmp.complete(), but it does not get expanded.

Steps to reproduce

  1. Enter Insert mode and type a character.
  2. Press <C-n> to open the completion menu (as mapped in my repro file).
  3. Observe the first item gets selected, but it does not get expanded.
  4. Further <C-n> and <C-p> inputs change the selection and do expand.
  5. In a default or minimal nvim config, observe that pressing <C-n> to open the menu also selects and expands the first menu entry.

Expected behavior

The auto-selected first menu item should expand in the insert field.

Actual behavior

The first menu item gets selected, but the text does not get expanded until additional <C-n> or <C-p> inputs.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions