tpope / vim-endwise

endwise.vim: Wisely add

Home Page:https://www.vim.org/scripts/script.php?script_id=2386

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conflic with CoC

benediktms opened this issue · comments

After installing endwise I ran into a bug where the coc#select_confim() gets confused and literally returns itself as a string where the cursor is:

pumvisible() ? coc#_select_confirm(): "\\                                                
\    

Any idea what could be causing this?

commented

You can try out:

inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>\<c-r>=EndwiseDiscretionary()\<CR>"

This queues endwise's completion after coc.vim.

Seams to work for me at least :)

inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>\<c-r>=EndwiseDiscretionary()\<CR>"

That didn't work for me, because endwise still added a mapping on top of that. I think the issue is that coc defines a <expr> mapping, but endwise can't handle that when it remaps <CR>.

Instead, I used a function to avoid the need for <expr>. This is working so far:

inoremap <silent> <CR> <C-r>=<SID>coc_confirm()<CR>
function! s:coc_confirm() abort
  if pumvisible()
    return coc#_select_confirm()
  else
    return "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
  endif
endfunction

Unfortunately incompatible. Guess it's more efficient to use snippets anyway.

For what it's worth, if you comment out just this line of the coc config, then the problem will go away. If I'm not mistaken, this code is only responsible for preselecting the first item, something you can get by without.

I could only solve sourcing vim-endwise and then using @thenoseman command. Like this:

Plug 'tpope/vim-endwise'
source /home/alex/.local/share/nvim/plugged/vim-endwise/plugin/endwise.vim

inoremap <silent><expr> <CR> pumvisible() ? coc#_select_confirm() :"\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>\<c-r>=EndwiseDiscretionary()\<CR>" 

Since I'm using vim-plug to install vim-endwise, I had to pass the absolute path.
If someone knows a better approach, please comment.

PS: That would probably fail the first time vim is launched, i.e., before the first :PlugInstall run.

I've tweaked the guard so that the source should no longer be necessary.

inoremap <silent><expr> <CR> pumvisible() ? coc#_select_confirm() :"\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>\<c-r>=EndwiseDiscretionary()\<CR>" 

Going to endorse this as the official solution. Since the <CR> map is already something you're dumping in your vimrc, I think it makes more sense for users to alter it directly rather than attempt surgery on it after the fact in Endwise.