Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enter conflicts with neocomplcache #22

Open
pjg opened this issue Aug 5, 2012 · 16 comments
Open

Enter conflicts with neocomplcache #22

pjg opened this issue Aug 5, 2012 · 16 comments

Comments

@pjg
Copy link

pjg commented Aug 5, 2012

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.

@blueyed
Copy link
Contributor

blueyed commented Sep 17, 2012

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 "<script>" but with "="), or by handing neocomplcache explicitly in endwise.

@blueyed
Copy link
Contributor

blueyed commented Sep 17, 2012

See also ervandew/supertab@c6d704c for inspiration.

@pjg
Copy link
Author

pjg commented Sep 17, 2012

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

blueyed added a commit to blueyed/vim-endwise that referenced this issue Sep 19, 2012
This allows to work around issues like issue tpope#22
(tpope#22)
tpope pushed a commit that referenced this issue Sep 19, 2012
This allows to work around issues like issue #22
(#22)
@blueyed
Copy link
Contributor

blueyed commented Feb 11, 2014

@pjg
Did you get this resolved back then?

You might want to check out my pull request, which improves the mapping setup: #50

@pjg
Copy link
Author

pjg commented Feb 11, 2014

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

@blueyed
Copy link
Contributor

blueyed commented Feb 11, 2014

Great.
This issue might get closed then probably.

YouCompleteMe+Eclim
👍

tpope added a commit that referenced this issue Apr 11, 2014
Potentially a partial replacement for remapping <CR>.

References #10, #14, #19, #22.
@chrisnicola
Copy link

Seem to have this same problem with YouCompleteMe actually

@blueyed
Copy link
Contributor

blueyed commented Jun 17, 2014

@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()

@jfelchner
Copy link

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

@bjeanes
Copy link

bjeanes commented Dec 11, 2018

I'm also experiencing this. It conflicts with coc.nvim causing hitting 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

@Mange
Copy link

Mange commented Apr 18, 2019

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

@GabeDuarteM
Copy link

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

@parmort
Copy link

parmort commented Nov 16, 2019

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.

@Mange
Copy link

Mange commented Nov 16, 2019

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?

@parmort
Copy link

parmort commented Nov 16, 2019

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

janlazo added a commit to janlazo/dotvim8 that referenced this issue Nov 17, 2019
vim-endwise mappings conflict with coc.nvim recommended mappings.
autocompletion and colorscheme plugins rely on filetype plugins
to provide syntax context for the current buffer.

Port solution from tpope/vim-endwise#22 (comment) to make both work together.
janlazo added a commit to janlazo/dotvim8 that referenced this issue Nov 18, 2019
vim-endwise mappings conflict with coc.nvim recommended mappings.
autocompletion and colorscheme plugins rely on filetype plugins
to provide syntax context for the current buffer.

Port solution from tpope/vim-endwise#22 (comment) to make both work together.
@Th3Whit3Wolf
Copy link

Th3Whit3Wolf commented Jul 1, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants