Deoplete.nvim: Trigger snippet expand on selection in menu

Created on 21 Apr 2017  路  6Comments  路  Source: Shougo/deoplete.nvim

Since I'm not facing a bug, I do not need to provide an init.vim and scenarios to reproduce it.

What I'm searching for is further integration with snippets. So far, I understand that neosnippet expands its snippet on TAB, and Deoplete.nvim makes it possible to cycle through all the suggestions with TAB. It places the selection directly into the file that is being edited.

Is it possible to trigger the expand of Neosnippet or any other snippet tool when the suggestion is selected in the menu? If so, can someone explain to me where I need to look?

Most helpful comment

Unfortunately, it is not possible.
It is Vim's feature.

All 6 comments

    " SuperTab like snippets' behavior.
    " Note: It must be "imap" and "smap".  It uses <Plug> mappings.
    imap <expr><TAB>
     \ pumvisible() ? "\<C-n>" :
     \ neosnippet#expandable_or_jumpable() ?
     \    "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
    smap <expr><TAB> neosnippet#expandable_or_jumpable() ?
     \ "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"

This does not expand a snippet upon selection.

Init.vim

call plug#begin('~/.config/nvim/plugged')
Plug 'Shougo/dein.vim' " dein itself
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'Shougo/neosnippet.vim' " Snippets
Plug 'Shougo/neosnippet-snippets'
call plug#end()

let g:deoplete#enable_at_startup = 1
imap <expr><TAB>
    \ pumvisible() ? "\<C-n>" :
    \ neosnippet#expandable_or_jumpable() ?
    \    "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
smap <expr><TAB> neosnippet#expandable_or_jumpable() ?
    \ "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"

To reproduce:

  • create an empty .py file
  • type ipdb
  • the suggestion does not expand upon selection

Please use here.

imap <expr><TAB>
     \ neosnippet#expandable_or_jumpable() ?
     \    "\<Plug>(neosnippet_expand_or_jump)" :
         \   \ pumvisible() ? "\<C-n>" : "\<TAB>"

Thanks for all the help so far man!

There was a \ to much but this works:

imap <expr><TAB>
     \ neosnippet#expandable_or_jumpable() ?
     \    "\<Plug>(neosnippet_expand_or_jump)" :
         \    pumvisible() ? "\<C-n>" : "\<TAB>"

The behavior is a bit different from what I'd expect, the expand gets triggered when i use tab and the whole snippet shortcut is typed. I can still use <C-n> instead of <TAB> to navigate between the options, then select the snippet which I want to expand, but wouldn't it be easier if i can cycle through expanded snippets? Normally it places the suggestion on selection, but not an expanded snippet. Is this possible?

Unfortunately, it is not possible.
It is Vim's feature.

Ok, thank you for your support! I really appreciate it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shibumi picture shibumi  路  4Comments

firedev picture firedev  路  4Comments

monicao picture monicao  路  3Comments

callmekohei picture callmekohei  路  5Comments

letharion picture letharion  路  5Comments