My completion mappings scheme with coc is the following:
<c-@>
(ctrl-space): trigger the menu / use the selected item (or the first one)<c-j>
and<c-k>
: navigate the list (or also trigger the menu)<c-n>
and<c-p>
: jump between snippets placeholders
Which translates as:
inoremap <expr> <c-@> pumvisible() ? coc#_select_confirm() : coc#refresh()
inoremap <expr> <c-j> pumvisible() ? "\<C-n>" : coc#refresh()
inoremap <expr> <c-k> pumvisible() ? "\<C-p>" : coc#refresh()
let g:coc_snippet_next = <c-n>
let g:coc_snippet_prev = <c-p>
This works pretty well (and I'm glad each key does only one thing and my "tab" and "enter", which are <c-i>
and <c-m>
, are not remapped).
Unfortunately, when the popup completion menu is shown, the default behavior (navigate the menu) takes over the global variable given by the plugin.
I tried the following (and more) to definitely shut the mapping when the menu is visible, with no success:
inoremap <expr> <c-n> pumvisible() ? "\<c-y>" : ""
inoremap <expr> <c-n> pumvisible() ? "\<nop>" : "\<nop>"
inoremap <expr> <c-n> "\<nop>"
inoremap <c-n> <nop>
Doing so, I noticed <c-n>
and <c-p>
seem to be affected only by the pumvisible()
check for the regular pop menu, and not by the coc
pop menu.
It's really driving me nuts since the above mappings, which use the same check, do work as intended.
Also, there's something in the help from coc
which could possibly point the the right direction:
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
It uses coc
's functions, which are not documented. I guess there's one to jump between placeholders, but I'm not able to find id.
Thanks for your time!