1

I successfully installed CoC in my Vim to have some code-suggestions/completions while coding in Rust.

It works fine, but I want make the suggestion-box only show up when I press a key-shortcut (E.g Cmd + x)

1

According to coc readme you can trigger completion manually with:

" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()

NOTE that not every terminal supports <c-space>...

I don't know for sure how to map cmd in vim... Probably D or something:

" Use <CMD-x> to trigger completion.
inoremap <silent><expr> <D-x> coc#refresh()

Example with <C-k> that should work with most terminals:

" Use <C-k> to trigger completion.
inoremap <silent><expr> <C-k> coc#refresh()

To turn off autocompletion for coc -- as stated in coc help, you have to add configuration to coc json file:

  1. run :CocConfig
  2. in the opened coc-settings.json file add:
{
  "suggest.autoTrigger": "none"
}

For reference, see :h CocConfig and :h coc-configuration (search for autoTrigger).

| improve this answer | |
  • The part to disable autoTrigger works perfectly! However manually opening the pMenu doesn't work yet. The default (c + space) just types a space and 'c' but opens nothing. The remap for D-x doesn't work. Maybe Cmd-key is a problem for the terminal Vim. How would I map Shift + e for example? Maybe that's easier. – O'Niel Mar 30 at 10:46
  • That is because of your terminal doesn't support this mapping. Try to change it to C-k for example. Shift + e is not very good as you it would trigger coc-refresh whenever you enter E letter (and will not be able to write a simple word with E -- Error, for example) – Maxim Kim Mar 30 at 11:06
  • Tried adding inoremap <silent><expr> <C-k> coc#refresh() to the bottom of vimrc, restarted Vim. Pressed Ctrl + k. Did not work. – O'Niel Mar 30 at 15:40
  • what is the output of :verbose imap <C-k>? – Maxim Kim Mar 30 at 16:58
  • and you do press it in insert mode, right? just to dblcheck – Maxim Kim Mar 30 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.