How to trigger autocomplete suggestion box in vim or neovim (Plugin neoclide/coc.vim)

10,316

Solution 1

I've commented in https://github.com/neoclide/coc.nvim/issues/2299#issuecomment-686293001

The suggestion box in your image is signatureHelp. If you want to reopen it, you need to trigger triggerCharacters in your function, usually is ( and ,. The triggerCharacters is defined by LS.

Solution 2

Yes, the answer is on the front page of CoC's github project. You need to map something to coc#refresh(). For instance, to use Ctrl + Space to trigger completion, you need to put the following in your vimrc:

inoremap <silent><expr> <c-space> coc#refresh()

There are more examples on the project's page.

Solution 3

TLDR: try this Ctrl+@

I found this in README of neoclide/coc.nvim:

" Use <c-space> to trigger completion.
if has('nvim')
  inoremap <silent><expr> <c-space> coc#refresh()
else
  inoremap <silent><expr> <c-@> coc#refresh()
endif

The weirdness here is that, Ctrl+Space is not working, despite using neovim NOT vim.

But there is a good trick to get your desired key binding as it appears from your terminal emulator point of view:

  1. Enter insert mode
  2. Press Ctrl+v
  3. Then press your keys you want to bind, Ctrl+Space

It seems that my terminal doesn't recognize using Ctrl and Space. "I think this is the real problem!"


Edit

Steps to solve it:

  1. I changed the default coc config a little bit:
    inoremap <silent><expr> <c-space> coc#refresh()
    inoremap <silent><expr> <c-@> coc#refresh()
    
  2. I tried bash as I was using zsh as a shell, but the problem is still there.
  3. Then I tried another terminal emulator and the problem is solved, alhamdulilah.
Share:
10,316
dev-stefancho
Author by

dev-stefancho

Web developer, Frontend Developer. Language Korean, English

Updated on June 14, 2022

Comments

  • dev-stefancho
    dev-stefancho almost 2 years

    I'm Neovim user

    and I use Plugin neoclide/coc.vim for autocompletion

    but when my cursor focus out, I can not get suggestion box again
    (How can I call this box? suggest box or hint box? I want to know this box name)

    I want to trigger it and see again, Is there any command or variable for this?

    enter image description here