To autocomplete by pressing enter, I have the following map setup to work with neocomplete.vim:
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
return pumvisible() ? "\<c-y>" : "\<CR>"
endfunction
This works fine. To explain, pumvisible()
returns true when neocomplete's PopUpMenu is showing. <c-y>
chooses the selected word, inserting it after the insert mode cursor, and closes the neocomplete popup.
I want to extend this mapping so that, when the autocompleted word is a "snippet" word, the neosnippet.vim plugin will automatically expand it. This is what I tried:
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
return pumvisible() ? "\<c-y>\<Plug>(neosnippet_expand_or_jump)" : "\<CR>"
endfunction
Instead of expanding the snippet word, this results in the following being inserted directly into the text where the cursor is:
<t_ý>S(neosnippet_expand_or_jump)`
How can I fix this and make it work?
Possibly relevent note: If I return to the working version of the code (first one above), hit "enter", then manually type <C-k>
(while still in insert mode), the snippet expands correctly. Here is the mapping setup for <C-k>
:
imap <C-k> <Plug>(neosnippet_expand_or_jump)