prabirshrestha / asyncomplete.vim

async completion in pure vim script for vim8 and neovim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

<CR> not functioning as expected while popupmenu is open

jacquesh opened this issue · comments

The problem

When the autocomplete popupmenu is visible, I expect to still function as it always has: create a new line and move to it.
If we're on a new line then there's no text in front of the cursor so I'd expect that we'd stop auto-completion (in particular by closing the popupmenu). However if I hit while completing without having selected a completion, it does nothing. If I type such that the popupmenu shows, hit to select a completion and then hit , it works as expected (makes a newline and closes the PUM).

I am using gvim, compiled from source at version 8.2.96 on Windows 10 x64. I looked through the help file but didn't see anything that stood out as likely to be an option that might change this behaviour. I'm not sure why one might want asyncomplete to just eat so this seems like a bug?

Here's a gif of it in action, using the vimrc below (the flash is me hitting ):
vim-pum

Steps to reproduce

  1. Use the following vimrc (you may need to modify WORKINGDIR to point to your plugin directory/manager, I used vim-plug)
let $WORKINGDIR=$HOME . "/.config/vim"
set runtimepath=$WORKINGDIR,$VIMRUNTIME

call plug#begin($HOME . '/.config/vim/plugged')
Plug 'prabirshrestha/asyncomplete.vim' " Async autocompletion with pluggable sources
Plug 'prabirshrestha/asyncomplete-buffer.vim' " Asyncomplete source that reads from the current buffer
call plug#end()

function! ClosePUMAndCR()
	call asyncomplete#close_popup()
	return "\<CR> \<CR>"
endfunction
"inoremap <expr> <CR> pumvisible() ? ClosePUMAndCR() : "\<CR>"

autocmd User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#buffer#get_source_options({
    \ 'name': 'buffer',
    \ 'allowlist': ['*'],
    \ 'completor': function('asyncomplete#sources#buffer#completor'),
    \ }))
  1. Open the above vimrc, go to a new line and type in func. You should get a popup menu suggesting an autocomplete to function. Without hitting or , instead hit
  2. I would expect this to enter a new line, thereby closing the popupmenu. Instead what happens is the PUM flashes and my cursor doesn't move.

If you then uncomment the insert-mode mapping, the above will function as expected. However it required that we script two keypresses after requesting that the PUM be closed so while this is a successful workaround, I'd prefer not to do this long-term.

you need to manually map inoremap for <CR> refer to #117 for examples.

Ah, I thought I'd searched for similar issues. Thanks for pointing me in the right direction.

For any future readers: I fiddled around a bit and landed on the following (embarrassingly simple) mapping that does the trick:
inoremap <expr> <CR> pumvisible() ? "\<C-y>\<CR>" : "\<CR>"

Feel free to send a PR to docs if you would like to.