Deoplete.nvim: "Enter" on exact(?) match dismisses popup-menu, but does not adds linebreak

Created on 29 Nov 2015  路  10Comments  路  Source: Shougo/deoplete.nvim

TEST CASE:

  1. nvim foo
  2. Insert foobarbaz
  3. Press Enter
  4. Insert foobarbaz again, a completion for it will be shown.
  5. Press Enter

EXPECTED RESULT:
You are on line 3 now.

ACTUAL RESULT:
The pressing of Enter dismisses the completion menu.

This appears to be related to when there's an exact match.
(When this happened to me before, I've experimented with setting completeopt+=noselect,noinsert explicitly, but that does not seem to help now.)

Minimal vimrc:

set runtimepath+=~/.vim/neobundles/deoplete/
let g:deoplete#enable_at_startup = 1

Most helpful comment

It is Vim's feature.
Please see :help popupmenu-keys

You should remap <CR> key.

" <CR>: close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
  return deoplete#mappings#smart_close_popup() . "\<CR>"
endfunction

All 10 comments

It is Vim's feature.
Please see :help popupmenu-keys

You should remap <CR> key.

" <CR>: close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
  return deoplete#mappings#smart_close_popup() . "\<CR>"
endfunction

@Shougo I was also troubled, Thank you for the information :)

It does not seem to work as described though?!

I am not using the cursor keys or some other method to select the entry.

The 2nd state is:

  1. A cursor key has been used to select another match. The match was not
    inserted then, only the entry in the popup menu is highlighted.

The behavior of the key depends on the state you are in:
first state: Use the text as it is and insert a line break.
second state: Insert the currently selected match.
third state: Use the text as it is and insert a line break.

In other words: If you used the cursor keys to select another entry in the
list of matches then the key inserts that match. If you typed
something else then inserts a line break.

@blueyed FYI, I do not understand completely your ideal behavior, but

inoremap <silent><expr><CR> pumvisible() ? deoplete#mappings#close_popup()."\<CR>" : "\<CR>"

It will be

  1. Insert first foobarbaz - does not use the completion
  2. Enter - move next line
  3. Insert second foobarbaz - but when insert foob, open popupmenu
  4. Select foobarbaz in popupmenu use <CR>, will be inserted foobarbaz on buffer, and move next line

If you do not want to move to the next line after the selected word, remove ."\<CR>"

inoremap <silent><expr><CR> pumvisible() ? deoplete#mappings#close_popup() : "\<CR>"

Use this setting sample screencast:
https://asciinema.org/a/30892

@zchee
Thanks. deoplete#mappings#smart_close_popup() works for me.

I was referring to @Shougo statement that this is a (Neo)Vim feature.
It is not working as documented for me.

@blueyed Yes, it is not well documented behavior.
If you input "fo" (just the popup is generated), you can insert new line by <CR>.
But if you input "foobarbaz", it seems narrowing state and same with 2nd state.

  1. A cursor key has been used to select another match. The match was not
    inserted then, only the entry in the popup menu is highlighted.

So, the <CR> just close popup menu. It is same behavior with Vim/neovim. deoplete/neocomplete is just completion plugin. I cannot fix it.

Thanks for your explanation.

A cursor key has been used to select another match.

That's not the case though, but it appears to behave like that.

As said by @zchee, we should use deoplete#mappings#close_popup() instead of deoplete#mappings#smart_close_popup() if we want the completion to occur.

Could the FAQ be updated accordingly, please?

Documentation updated.

I have also
inoremap <expr> <TAB> pumvisible() ? "\<C-y>\<cr>" : "\<TAB>"

along with

" <CR>: close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
    return deoplete#mappings#smart_close_popup() . "\<CR>"
endfunction

And now my Enter creates a new line

Was this page helpful?
0 / 5 - 0 ratings

Related issues

westlywright picture westlywright  路  6Comments

ChristianChiarulli picture ChristianChiarulli  路  5Comments

Zundrium picture Zundrium  路  6Comments

nikitavoloboev picture nikitavoloboev  路  3Comments

pappasam picture pappasam  路  4Comments