Hangs with mapping inoremap <expr> <cr> pumvisible() ? '<c-y>' : '<cr>'
astier opened this issue · 10 comments
System
- vim-closer 26bba80
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
- Create a new file with a filetype which is supported bug vim-closer:
vim bug.sh
- Enter insert-mode, type
{
and press<cr>
:i{<cr>
- 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
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.
same issue, temporarily switching to coc-pairs
, although I'd love to have closer
work
Can confirm that I also have this issue, using COQ.nvim
+1 here
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. 😅
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.
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.
A fix was just merged, give it a go!
Seems to work. Thanks for fixing!