I have a question on coc.nvim issue but the author reply me with the message:
Learn viml, the plugin already provided what you need.
opened 01:08AM - 05 Apr 22 UTC
closed 01:21AM - 05 Apr 22 UTC
In LunarVim, they can use `<Tab>` for both navigate next item and snippet expand… . I put the script based on coc-nvim document to my vimrc.
```
Map <tab> for trigger completion, completion confirm, snippet expand and jump
like VSCode. >
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>'
```
I only can use `<tab>` for snippet jumping, popup navigation doesn't work, it always pick the first item in list.
https://user-images.githubusercontent.com/75968004/161657971-fa8af36c-7e75-4522-a3c9-e47795eeb360.mp4
Config:
```
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: Coc-nvim "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Completion settings
"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() ? coc#_select_confirm() :
"\ coc#expandableOrJumpable() ?
"\ "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
"\ <SID>check_back_space() ? "\<TAB>" :
"\ coc#refresh()
"inoremap <silent><expr> <TAB>
"\ pumvisible() ? "\<C-n>" :
"\ <SID>check_back_space() ? "\<TAB>" :
"\ coc#refresh()
""""""""""""""""""""""""""""""""""""""""""""""""""""""
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>'
autocmd
94d13f69-3e60-4a7a-bd6b-2c402bae1ad5
0d6059ae-d149-44a6-a91a-c164ee5e3ce5
augroup AU_NAME
autocmd!
autocmd BufRead,BufNewFile *.ext,*.ext3|<buffer[=N]>
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Select the first completion item and confirm the completion when no item has been selected:
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
"let g:coc_snippet_next = '<M-l>'
"let g:coc_snippet_prev = '<M-h>'
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-d> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-u> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-d> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-u> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-d> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-u> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
if exists('g:did_coc_loaded')
autocmd CursorHold * silent call CocActionAsync('highlight')
endif
let g:coc_global_extensions = ['coc-json',
\'coc-vimlsp',
\'coc-snippets',
\'coc-powershell',
\'coc-markdownlint',]
```
I’m just a normal user who wants to use the plugin and wants to ask the question for help.
Does anyone have an idea for my issues? Thanks in advance for you help.
windwp
April 6, 2022, 5:48am
2
are you try to replace coc#select_confirn with <c-n>
or some thing similar coc#gonext .
if it is not working you need create a custom mapping function it will return empty if pumvisible then call feedkey <c-n>
.
ofcourse like the maintainer say you need learn viml
Thanks, but it just works for with it didn’t work.
Here is my config, can you fix it for me, I’m not familiar with VimL.
"Completion settings
"Use <tab> for trigger completion and navigate to the next complete item
inoremap <silent><expr> <Tab>
\ pumvisible() ? "\<C-n>" :
\ coc#expandableOrJumpable() ?
\ "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
\ <SID>check_back_space() ? "\<Tab>" :
\ coc#refresh()
inoremap <silent><expr> <S-Tab>
\ pumvisible() ? "\<C-p>" :
\ coc#expandableOrJumpable() ?
\ "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-pre',''])\<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
"Select the first completion item and confirm the completion when no item has been selected:
inoremap <silent><expr> <CR> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
let g:coc_snippet_next = '<Tab>'
let g:coc_snippet_prev = '<S-Tab>'