vim-endwise icon indicating copy to clipboard operation
vim-endwise copied to clipboard

Enter conflicts with neocomplcache

Open pjg opened this issue 13 years ago • 16 comments
trafficstars

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.

pjg avatar Aug 05 '12 16:08 pjg

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 "

blueyed avatar Sep 17 '12 16:09 blueyed

See also https://github.com/ervandew/supertab/commit/c6d704c6daf64b85828d99a88f9099efc7e01299 for inspiration.

blueyed avatar Sep 17 '12 16:09 blueyed

@blueyed that is a good pointer! I was using supertab previously with vim-endwise without any problems.

pjg avatar Sep 17 '12 16:09 pjg

@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

blueyed avatar Feb 11 '14 19:02 blueyed

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).

pjg avatar Feb 11 '14 20:02 pjg

Great. This issue might get closed then probably.

YouCompleteMe+Eclim :+1:

blueyed avatar Feb 11 '14 22:02 blueyed

Seem to have this same problem with YouCompleteMe actually

chrisnicola avatar Jun 17 '14 22:06 chrisnicola

@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 avatar Jun 17 '14 22:06 blueyed

@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. ❤

jfelchner avatar May 15 '17 05:05 jfelchner

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

bjeanes avatar Dec 11 '18 01:12 bjeanes

Is it possible to fix this inside this library? I had to disable it because I'm using CoC, but I really miss it.

Mange avatar Apr 18 '19 07:04 Mange

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

GabeDuarteM avatar May 04 '19 20:05 GabeDuarteM

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.

parmort avatar Nov 16 '19 16:11 parmort

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.

That only writes <Plug>DiscretionaryEnd when I press enter.

def foo
  <Plug>DiscretionaryEnd

Did you miss some characters here? Maybe some literal escape characters?

Mange avatar Nov 16 '19 23:11 Mange

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

parmort avatar Nov 16 '19 23:11 parmort

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

Th3Whit3Wolf avatar Jul 01 '20 20:07 Th3Whit3Wolf