Coc.nvim: Issue on pressing tab at the end of a word

Created on 16 Mar 2019  ·  5Comments  ·  Source: neoclide/coc.nvim

I am using the example vimrc given in README.md.

The question is, when there is no candidate for completion and the cursor is at the end of a word, tapping tab results nothing.

In my opinion, the ideal behavior for this case should be moving the cursor to next tab position, other than searching completion candidates in an empty list.

I believe this is caused by

inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

in given vimrc configuration

How can I fix it without changing the normal behavior when the completion candidate list is not empty? Thanks!

question

Most helpful comment

should be moving the cursor to next tab position.

What does next tab position means?

It means inserting a tab character.

I am using the example vimrc given in README.md.
I believe this is caused by
...

Indeed. Check this wiki page: https://github.com/neoclide/coc.nvim/wiki/Completion-with-sources#improve-completion-experience

inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"

The code above should make it work the way you want.
When I comment that line out of vimrc I get the behaviour you described. It remaps tab back to tab when there is no completion window open.

All 5 comments

should be moving the cursor to next tab position.

What does next tab position means?

The cursor is at the end of a word doesn't means the completion request would return empty results, it's sometimes.

should be moving the cursor to next tab position.

What does next tab position means?

It means inserting a tab character.

I am using the example vimrc given in README.md.
I believe this is caused by
...

Indeed. Check this wiki page: https://github.com/neoclide/coc.nvim/wiki/Completion-with-sources#improve-completion-experience

inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"

The code above should make it work the way you want.
When I comment that line out of vimrc I get the behaviour you described. It remaps tab back to tab when there is no completion window open.

The example in Readme is for trigger completion when there is word character before, but what you need is not trigger the completion, so you have to create your own keymap for <Tab>.

inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"

The code above should make it work the way you want.
When I comment that line out of vimrc I get the behaviour you described. It remaps tab back to tab when there is no completion window open.

This works. Thank you @DzKaki !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FrankLA0203 picture FrankLA0203  ·  3Comments

MacGuffinLife picture MacGuffinLife  ·  4Comments

iago-lito picture iago-lito  ·  3Comments

LinArcX picture LinArcX  ·  4Comments

zhou13 picture zhou13  ·  3Comments