vim-endwise
vim-endwise copied to clipboard
Enter conflicts with neocomplcache
This is cross-posting from neocomplcache issues as recommended by @Shougo.
Note that I'm also using vim-endwise. Using the recommended snippet from doc/neocomplcache.txt (see 351a2f102460):
inoremap <expr><silent> <CR> <SID>my_cr_function()
function! s:my_cr_function()
return pumvisible() ? neocomplcache#close_popup() . "\<CR>" : "\<CR>"
endfunction
when pressing enter when choosing autocompletion from the menu it selects this autocompletion and also moves you to the next line (i.e. <CR> is literally inserted), while using the previous snippet for <CR> mapping in insert mode (inoremap <expr><CR> neocomplcache#smart_close_popup() . "\<CR>") without the vim-endwise plugin when pressing <cr> in insert mode on autocomplete menu item it would only select the item from the autocompletion menu and would not insert a <cr> in the code.
Also note that using this snippet: inoremap <expr><CR> neocomplcache#smart_close_popup() . "\<CR>" conflicts with vim-endwise, which is issue #88.
There is a test in endwise.vim which invokes/includes the previously defined mapping:
elseif maparg('<CR>','i') =~ '<CR>'
exe "imap <script> <C-X><CR> ".maparg('<CR>','i')."<SID>AlwaysEnd"
exe "imap <script> <CR> ".maparg('<CR>','i')."<SID>DiscretionaryEnd"
Considering the recommended mapping of inoremap <expr><CR> neocomplcache#smart_close_popup() . "\<CR>" this will result in the text itself being inserted.
This could maybe be solved by endwise checking for the mapping to be a script (e.g. via maparg's dict option/mode) and acting accordingly (if that is possible), by using another mapping method with neocomplcache (e.g. without "
See also https://github.com/ervandew/supertab/commit/c6d704c6daf64b85828d99a88f9099efc7e01299 for inspiration.
@blueyed that is a good pointer! I was using supertab previously with vim-endwise without any problems.
@pjg Did you get this resolved back then?
You might want to check out my pull request, which improves the mapping setup: https://github.com/tpope/vim-endwise/pull/50
Appreciate your effort! I have moved on to YouCompleteMe+Eclim for my tab-completion needs, though (cannot beat java parsing my ruby code and presenting me the best tab-completions possible).
Great. This issue might get closed then probably.
YouCompleteMe+Eclim :+1:
Seem to have this same problem with YouCompleteMe actually
@chrisnicola
What is your mapping for :imap <cr>?
(I am using a custom function, where I chain multiple plugins:)
fun! My_CR_map()
" "<CR>" via delimitMateCR
let r = "\<Plug>delimitMateCR"
if maparg('<Plug>CursorCrossCR', 'i')
" requires vim 704
let r .= "\<Plug>CursorCrossCR"
endif
let r .= "\<Plug>DiscretionaryEnd"
return r
endfun
imap <expr> <CR> My_CR_map()
@blueyed I know this is an old issue but I had to message you because this previous comment was the key for me and kept me from throwing my laptop out the window. Thank you so much for putting this here. ❤
I'm also experiencing this. It conflicts with coc.nvim causing hitting <CR> to result in printing out the expression to the buffer:
before hitting enter for completion:
foo = partial_expr|
after:
foo = partial_expr
pumvisible() ? "\" : "\\
"|
The coc.nvim mapping definition is:
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
After endwise remaps it, :verbose imap <CR> shows:
i <CR> & pumvisible() ? "\<C-Y>" : "\<C-G>u\<CR>"<SNR>25_DiscretionaryEnd
Is it possible to fix this inside this library? I had to disable it because I'm using CoC, but I really miss it.
I also use Coc, and I'm having the same problem @bjeanes described :/
Is at least any workaround on this? For now, I disabled vim-endwise, but I'd like to continue using it
inoremap <expr> <Plug>CustomCocCR pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
imap <CR> <Plug>CustomCocCR<Plug>DiscretionaryEnd
Here's my solution to the CoC problem. Seems to work fine.
inoremap <expr> <Plug>CustomCocCR pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" imap <CR> <Plug>CustomCocCR<Plug>DiscretionaryEndHere's my solution to the CoC problem. Seems to work fine.
That only writes <Plug>DiscretionaryEnd when I press enter.
def foo
<Plug>DiscretionaryEnd
Did you miss some characters here? Maybe some literal escape characters?
Make sure that all the modifiers to the mapping commands are correct. The imap and inoremap are important as well. Those are some of the problems that I encountered.
Here is a test vimrc you can do (run vim -u <path-to-file>)
set rtp+=~/.vim
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-endwise'
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
call plug#end()
let g:endwise_no_mappings = v:true
inoremap <expr> <Plug>CustomCocCR pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
imap <CR> <Plug>CustomCocCR<Plug>DiscretionaryEnd
I'm so glad I found this issues. I love this plugin and I really like coc.
Some of you may like
let g:endwise_no_mappings = v:true
inoremap <expr> <Plug>CustomCocCR pumvisible() ? coc#_select_confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
imap <CR> <Plug>CustomCocCR<Plug>DiscretionaryEnd
To auto-select the first completion item and notify coc.nvim to format on enter