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

Hangs with mapping inoremap <expr> <cr> pumvisible() ? '<c-y>' : '<cr>' #37

Closed
astier opened this issue Jun 1, 2021 · 10 comments · Fixed by #40
Closed

Hangs with mapping inoremap <expr> <cr> pumvisible() ? '<c-y>' : '<cr>' #37

astier opened this issue Jun 1, 2021 · 10 comments · Fixed by #40

Comments

@astier
Copy link

astier commented Jun 1, 2021

System

Reproducible with all the following vim-version:

  • NVIM v0.5.0-dev+1367-g27c616d68
  • NVIM v0.4.4
  • VIM 8.2

Problem

vim-closer hangs when trying to close a bracket if an insert-mapping exists which executes <expr> dependent on pumvisible().

VIMRC

call plug#begin()
    Plug 'rstacruz/vim-closer'
call plug#end()
filetype plugin on
inoremap <expr> <cr> pumvisible() ? '<c-y>' : '<cr>' 

Reproduce

  1. Create a new file with a filetype which is supported bug vim-closer: vim bug.sh
  2. Enter insert-mode, type { and press <cr>: i{<cr>
  3. Vim should hang now. Abort operation by pressing <c-c>

It should be visible that vim-closer created a long line which looks like this:

{pumvisible() ? '' : 'pumvisible() ? '' : 'pumvisible() ? '' :

It essentially pastes {pumvisible() ? '' : over and over.

Related

#22
#25

@w1zd
Copy link

w1zd commented Jun 21, 2021

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

pastes {pumvisible() ? '' : over and over again.

vim-hyperstyle has the same issue.

@gegnew
Copy link

gegnew commented Aug 25, 2021

same issue, temporarily switching to coc-pairs, although I'd love to have closer work

@IllustratedMan-code
Copy link

Can confirm that I also have this issue, using COQ.nvim

@geofffranks
Copy link

+1 here

@rstacruz
Copy link
Owner

rstacruz commented Jan 12, 2022 via email

@laomaiweng
Copy link

I'm not sure that's best fixed on your end rather than on the completers' (non-expr mapping) or Neovim's end (ability to "chain" mappings?), but perhaps at least put a warning in the README? This bug affects multiple auto-completers, isn't trivial to isolate, and is quite disruptive (complete neovim hang), so I figure people would be glad to know before getting bitten.

It took me days to find out this was the root cause for my hangs, I'd sure have appreciated a heads up. 😅

@rstacruz
Copy link
Owner

rstacruz commented Feb 7, 2022

I added a note to the README now. Thanks all, would appreciate some ideas on how to fix this.

Someone has posted a workaround in #22.

@tpope
Copy link

tpope commented Jul 18, 2022

I recently solved this for Endwise and Eunuch. My recommended approach would be to give closer#close() an optional ... argument and add something like this to the top: https://github.com/tpope/vim-eunuch/blob/74e0e1662cc9ed3d58ba3e3de20eb30ac4039956/plugin/eunuch.vim#L438-L440

Then when defining the <CR> map, you can chain to an existing <expr> map by passing the original definition as an argument: https://github.com/tpope/vim-eunuch/blob/74e0e1662cc9ed3d58ba3e3de20eb30ac4039956/plugin/eunuch.vim#L468-L485

P.S. Endwise and Eunuch now default to this approach, which means vim-closer now suffers from this issue if either is installed.

jasonwoodland added a commit to jasonwoodland/vim-closer that referenced this issue Jul 30, 2022
jasonwoodland added a commit to jasonwoodland/vim-closer that referenced this issue Jul 30, 2022
jasonwoodland added a commit to jasonwoodland/vim-closer that referenced this issue Jul 30, 2022
@rstacruz
Copy link
Owner

rstacruz commented Aug 9, 2022

A fix was just merged, give it a go!

@mjs
Copy link

mjs commented Aug 14, 2022

Seems to work. Thanks for fixing!

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

Successfully merging a pull request may close this issue.

9 participants