2

I'm using coc.nvim for autocomplete and when the popup menu appears, I'd like Tab to select the first item and close the menu. At the moment I've keybinded Tab to <C-n><CR>, but the <CR> actually puts in a line return which is not what I want.

inoremap <expr> <Tab> pumvisible() ? "\<C-n><Space>" : "<Tab>"
1
  • Not sure if it works with the plugin, but <C-Y> is used to accept the completion. See :help popupmenu-keys Commented Oct 15, 2021 at 1:06

3 Answers 3

4

After struggling for so long and trying these things I realised it works out the box fine.

To select the first item in the dropdown list press: ctrl+y.

Press: ctrl+n select the next item in the drop down list.

Press: ctrl+p to select the previous item in the drop down list.

To use tab and shift tab as well to navigate next and previous items see the documentation.

To use tab to select first item in the drop down list below the above documentations config:

inoremap <expr> <TAB> pumvisible() ? "\<C-y>" : "\<C-g>u\<TAB>"
Sign up to request clarification or add additional context in comments.

Comments

2

I found the answer the coc.nvim's example docs:

https://github.com/neoclide/coc.nvim/blob/e1a4ce4d95d1d89b6dd31019cc4387425aa09b86/doc/coc.txt#L892-L909

inoremap <silent><expr> <TAB>
      \ pumvisible() ? coc#_select_confirm() :
      \ coc#expandableOrJumpable() ?
      \ "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()

    function! s:check_back_space() abort
      let col = col('.') - 1
      return !col || getline('.')[col - 1]  =~# '\s'
    endfunction

    let g:coc_snippet_next = '<tab>'

Works like an absolute charm.

1 Comment

Tabs work for autocompletion, but dont work as normal for creating tabs. I get the following error each time i press tab: "Error on request (snippetcheck): Vim(return) :Error invoking 'snippitCheck' on channel 3 (coc)..."
1

Try inoremap <expr> <Tab> pumvisible() ? coc#_select_confirm() : "<Tab>".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.