Ultisnips: Ultisnips and Deoplete mapping works only after reloading init.vim

Created on 30 Aug 2016  路  9Comments  路  Source: SirVer/ultisnips

After installing deoplete and mapping the tab key to code completion via adding the below code to my init.vim, the deoplete completion would only work after reloading init.vim. Someone posted this same dilemma : https://github.com/Shougo/deoplete.nvim/issues/164
According to Shougo though it is a problem with Ultisnips.

in the init.vim...
inoremap <silent><expr> <TAB> \ pumvisible() ? "\<C-n>" : \ <SID>check_back_space() ? "\<TAB>" : \ deoplete#mappings#manual_complete() function! s:check_back_space() abort "{{{ let col = col('.') - 1 return !col || getline('.')[col - 1] =~ '\s' endfunction"}}}

All 9 comments

I think <TAB> mapping is overwritten by UltiSnips to expand snippets.
You should check it by verbose imap <TAB>.

verbose imap <TAB> displays the tab mapping in my init.vim file I posted above. It doesn't seem like it's being overwritten.
Right now my tab key scrolls through options in the snippet/completion popup window. I think that I would have to map Ultisnips completion to a key other than <TAB>. Otherwise I'm not sure how it differentiate between scrolling through options and choosing one of the snippets to complete. I resolved the problem by setting snippet completion to the <leader>j key.

let mapleader = "\<space>"
let g:UltiSnipsExpandTrigger = "<leader>j"

Thanks! These mappings ended up working out. <TAB> seems to be working now for both scrolling through a set of potential autocompletions with deoplete and for expanding a snippet.

Sorry for my confusion, but can you specify how you got it working? The map_keys link is throwing me off. @Luis-Henriquez-Perez

Sure I use this function for Ultisnips:
'
function! ExpandSnippetOrReturn()
let snippet = UltiSnips#ExpandSnippetOrJump()
if g:ulti_expand_or_jump_res > 0
return snippet
else
return "\"
endif
endfunction

inoremap pumvisible() ? "=ExpandSnippetOrReturn()" : "\"
'
And this function for Deoplete:
`
inoremap
\ pumvisible() ? "\" :
\ check_back_space() ? "\" :
\ deoplete#mappings#manual_complete()

function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
`
And with this configuration deoplete's suggestions and ultisnips snippets show up and can be scrolled through with tab.

@Luis-Henriquez-Perez that seems to expand a snippet, but does not scroll through deoplete, and inside of a snippet will not go to the next mark. Maybe some configuration is missing? (I uncommented all other config I had and used only yours)

I think perhaps I did miss some more configurations. This is all my ultisnips config:
'
let g:UltiSnipsExpandTrigger = ""
let g:ulti_expand_or_jump_res = 0
let g:UltiSnipsEnableSnipMate = 1

let g:UltiSnipsSnippetsDir = "~/.config/nvim/UltiSnips"

function! ExpandSnippetOrReturn()
let snippet = UltiSnips#ExpandSnippetOrJump()
if g:ulti_expand_or_jump_res > 0
return snippet
else
return "\"
endif
endfunction

inoremap pumvisible() ? "=ExpandSnippetOrReturn()" : "\"
'
I think that the expandtrigger set to nothing is something important I left out before.

I got
No mapping found No mapping found
I think I should just stick with Tab and Shift Tab, then for expanding. Thank you though.

Was this page helpful?
0 / 5 - 0 ratings