0

I have this mapping in my vimrc:

imap <expr> <silent> <cr> neocomplete#mappings#close_popup() .
\ "<Plug>(neosnippet_jump_or_expand)"

and it's working great. When I press enter in a neocomplete popup it expands neosnippet but the problem is that <cr> will now work only for that and will not do a return line in insert mode.

1

Your question could be more elaborate. Perhaps you need something like:

imap <expr> <silent> <cr> neosnippet#expandable_or_jumpable() ?
            \ "<Plug>(neosnippet_expand_or_jump)" :
            \ neocomplete#mappings#close_popup()."\<CR>"
  • thats work in the case of function has a paramettre , but in the case of the function hase no paramettre it insert obg.fun()() it insert () two times – WALID BELRHALMIA Aug 23 '15 at 19:09
  • What function? Snippet? – VanLaser Aug 23 '15 at 19:34
  • plz look at : github.com/Shougo/neocomplete.vim/issues/461 you will understand the problem – WALID BELRHALMIA Aug 23 '15 at 19:48
  • i use neosnnipet with neocomplete for autocompletion , when i chose the function to autocomplete neosnippet generate automaticly a snippet to insert all function prototype – WALID BELRHALMIA Aug 23 '15 at 19:50
  • I will give you my advice: DON'T use the same key for autocompletion and snippet expansion. Use <C-j> for snippets. – VanLaser Aug 23 '15 at 19:52
0

This is the how complex insert mode mappings that involve the popup menu are usually written:

iemap <expr> <key> pumvisible() ? "\<another-key>" : "\<key>"

The ternary operator is used to "press" <another-key> if we are in a popup menu or <key> if we are not.

Assuming the snippet in your question works (I don't use those plugins), the following mapping should expand the selected snippet if you are in a popup menu or just "press" a regular <CR> otherwise.

imap <expr> <silent> <cr> pumvisible() ?
    \ neocomplete#mappings#close_popup() . "<Plug>(neosnippet_jump_or_expand)" :
    \ "\<CR>"

Note that the code above doesn't check if it is in a neobundle + neosnippet popup menu so I'd suggest putting all that in a function so that you have some elbow room for all your checks (and get a chance to use an actual if-elseif-else-endif conditional instead of a deep ternary operator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.