FAQ
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
- Enter Insert mode and type a character.
- Press
<C-n> to open the completion menu (as mapped in my repro file).
- Observe the first item gets selected, but it does not get expanded.
- Further
<C-n> and <C-p> inputs change the selection and do expand.
- 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
FAQ
Announcement
Minimal reproducible full config
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'scompleteopttomenu,menuone. The first entry does indeed get selected oncmp.complete(), but it does not get expanded.Steps to reproduce
<C-n>to open the completion menu (as mapped in my repro file).<C-n>and<C-p>inputs change the selection and do expand.<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