Meher Chaitanya
Meher Chaitanya

Reputation: 123

how to move up and down in vim(coc) autocomplete

I have recently shifted from youCompleteMe to ConquerOfCompletions and I have an issue in the auto-complete. when I was using YCM, to go through the auto-complete options tab used to work. But now in COC, I am using tsserver from the javascript completions I am not able to use tab. I know arrow keys are working but they are slowing my productivity. Please provide a solution for me to solve this issue where I can easily access the auto-complete options.

Thank You

Upvotes: 10

Views: 14267

Answers (2)

Akkd
Akkd

Reputation: 57

Mine wasn't working because of the space between "\ pumvisible", "\ <sid" and "\ coc.." in the snippet below.

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

Upvotes: 0

samsonjm
samsonjm

Reputation: 270

From the COC documentation, you need to edit your .vimrc https://github.com/neoclide/coc.nvim/wiki/Completion-with-sources:

Use or custom key for trigger completion

You can make use of coc#refresh() for trigger completion like this:

" use <tab> for trigger completion and navigate to the next complete item
function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~ '\s'
endfunction

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

Note: the could be remapped by another plugin, use :verbose imap to check if it's mapped as expected.

" use <c-space>for trigger completion
inoremap <silent><expr> <c-space> coc#refresh()

Some terminals may send when you press , so you could instead:

" use <c-space>for trigger completion
inoremap <silent><expr> <NUL> coc#refresh()

Improve the completion experience

Use <Tab> and <S-Tab> to navigate the completion list:

inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"

Upvotes: 12

Related Questions