devstefancho
devstefancho

Reputation: 2930

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

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

Upvotes: 12

Views: 37358

Answers (4)

Mohammed Samir
Mohammed Samir

Reputation: 416

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

Ops! nothing is inserted in my case. It seems that my terminal doesn't recognize using Ctrl and Space or understands this keybinding differently and intercepts it. So this is the real problem!

Things I tried to solve the problem:

  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, alhamdulillah.

Upvotes: 9

islamux
islamux

Reputation: 364

To Browse from suggestion box:

- <Tab > 

- <Ctrl - x> <Ctrl -f>

- <Ctrl - p ><Ctrl -n>

- <Ctrl - n ><Ctrl -n>

To Confirm selection

- <Ctrl - y>   

Upvotes: 7

fannheyward
fannheyward

Reputation: 19277

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.

Upvotes: 3

doopNudles
doopNudles

Reputation: 705

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.

Upvotes: 15

Related Questions