hrsh7th / nvim-cmp

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

cmp.complete() empty vsnip #1404

Open 0rtz opened 1 year ago

0rtz commented 1 year ago

FAQ

Announcement

Minimal reproducible full config

let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
  silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs  https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
  execute 'source ' . data_dir . '/autoload/plug.vim'
endif

call plug#begin()
" Completion
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/vim-vsnip-integ'
Plug 'rafamadriz/friendly-snippets'
call plug#end()

if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
    echom 'Some modules are missing, running :PlugInstall'
    PlugInstall --sync
endif

lua <<EOF
local cmp = require('cmp')

cmp.setup{
    mapping = {
        ['<C-Space>'] = cmp.mapping.complete({
            config = {
                sources = {
                    { name = 'vsnip' },
                }
            }
        }),
    },
    sources = {
        { name = 'vsnip' },
        { name = 'buffer' },
    }
}
EOF

Description

cmp.complete() does not work with vsnip/friendly-snippets

Steps to reproduce

Press Ctrl-Space in any file for which friendly snippets exists.

Expected behavior

Completion menu is shown

Actual behavior

Completion menu is not shown

Additional context

If I do not provide config argument to cmp.complete(), then a completion menu is shown, but only with buffer as a source. Completion for snippets are still missing on Ctrl-Space key press

gfcroft commented 1 year ago

For anyone who has a similar issue (ctrl-space not working when trying to trigger completion) I would recommend checking that your keyboard/terminal app/whatever in the input chain to vim is actually sending the input (ctrl-space) you think it is - particularly if you're on MacOs!

I questioned if my terminal app (iterm2) wasn't sending ctrl-Space through properly, so on iterm2 I turned on raw key reporting mode:

image

that showed me that space bar wouldn't register any input when ctrl was pressed at the same time

I then stumbled across this article which says that apparently a default system shortcut was made a while ago in macos that uses the ctrl-space combination

https://apple.stackexchange.com/a/351058

deselecting this shortcut like so solved my problem:

Screenshot 2023-03-16 at 22 34 38