diff --git a/.config/vim/vimrc.d/25-coc.vim b/.config/vim/vimrc.d/25-coc.vim index 4318dbb..620e155 100644 --- a/.config/vim/vimrc.d/25-coc.vim +++ b/.config/vim/vimrc.d/25-coc.vim @@ -13,20 +13,47 @@ set signcolumn=yes inoremap coc#pum#visible() ? coc#pum#next(1) : "\" inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" -" Use tab for trigger completion with characters ahead and navigate. -" NOTE: Use command ':verbose imap ' to make sure tab is not mapped by -" other plugin before putting this into your config. -inoremap - \ coc#pum#visible() ? coc#pum#next(1): - \ CheckBackspace() ? "\" : - \ coc#refresh() -inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" +" When no item was inserted yet, the first tab should insert the first item. +" `timer_start` is used to delay the execution to insert in the real buffer as +" far as I understand, otherwise vim will complain with 'E565: Not allowed to +" change text or change window'. It is the same method used by coc.nvim (e.g. in +" coc#pum#next). +function! CocPumNext(n) + if coc#pum#info()['inserted'] + return coc#pum#next(a:n) + else + call timer_start(10, { -> coc#pum#select(0,1,0) }) + return "\" + endif +endfunction +" When no item was inserted yet, the first shift-tab should select and insert +" the last item. See note about timer_start above. +function! CocPumPrev(n) + let l:info = coc#pum#info() + if l:info['inserted'] + return coc#pum#prev(a:n) + else + call timer_start(10, { -> coc#pum#select(l:info['size'] - 1,1,0) }) + return "\" + endif +endfunction +" Returns true if the cursor is at the beginning of the line or behind +" whitespace. function! CheckBackspace() abort let col = col('.') - 1 return !col || getline('.')[col - 1] =~# '\s' endfunction +" Use tab for trigger completion with characters ahead and navigate. +" NOTE: Use command ':verbose imap ' to make sure tab is not mapped by +" other plugin before putting this into your config. +inoremap + \ coc#pum#visible() ? CocPumNext(1) : + \ CheckBackspace() ? "\" : + \ coc#refresh() +inoremap coc#pum#visible() ? CocPumPrev(1) : "\" + " Use to trigger completion. if has('nvim') inoremap coc#refresh()