lifepillar / vim-mucomplete

Chained completion that works the way you want!
MIT License
912 stars 18 forks source link

<tab> does not jumps from ultisnips placeholder ${1:default} to $0 #172

Closed ghost closed 4 years ago

ghost commented 4 years ago

Say I have a snippet

snippet nt "note" b
\\note{
    $1
    $0
}
endsnippet

After I expand the snippet, I am able to jump from $1 to $0 using <tab>. But if I change $1 to ${1:default} to have a default text, the jump no longer works with <tab>. It still works with ultisnips forward trigger <C-right>. Here are my relevant mu-complete and ultisnips settings:

    Plug 'lifepillar/vim-mucomplete'
    set completeopt-=preview
    set completeopt+=menuone,noselect

    " Define default completion chain
    let g:mucomplete#chains = { 'default':
                \ [ 'ulti','omni','keyn','keyp','tags','path','line'] }

    Plug 'sirver/ultisnips'
    let g:UltiSnipsExpandTrigger="<C-right>"
    let g:UltiSnipsJumpForwardTrigger="<C-right>"
    let g:UltiSnipsJumpBackwardTrigger="<C-left>" 
    let g:UltiSnipsSnippetDirectories=["~/dotfiles/nvim/UltiSnips"]
    " Play nicely with mucomplete
    let g:ulti_expand_or_jump_res = 0
    fun! TryUltiSnips()
        if !pumvisible() " With the pop-up menu open, let Tab move down
            call UltiSnips#ExpandSnippetOrJump()
        endif
        return ''
    endf

    fun! TryMUcomplete()
        return g:ulti_expand_or_jump_res ? "" : "\<plug>(MUcompleteFwd)"
    endf

    let g:mucomplete#no_mappings  = 1 " Don't do any mappings I will do it myself

    " Extend completion
    imap <expr> <S-tab> mucomplete#extend_fwd("\<right>")

    " Cycle through completion chains
    imap <unique> <c-'> <plug>(MUcompleteCycFwd)
    imap <unique> <c-;> <plug>(MUcompleteCycBwd)

    " Try to expand snippet if fails, try completion.
    inoremap <plug>(TryUlti) <c-r>=TryUltiSnips()<cr>
    imap <expr> <silent> <plug>(TryMU) TryMUcomplete()
    imap <expr> <silent> <tab> "\<plug>(TryUlti)\<plug>(TryMU)"
    " Autoexpand if completed keyword is a snippet
    inoremap <silent> <expr> <plug>MyCR mucomplete#ultisnips#expand_snippet("\<cr>")
    imap <cr> <plug>MyCR
lifepillar commented 4 years ago

You need to change the default text before jumping.

lifepillar commented 4 years ago

I don't know what UltiSnips is doing under the hood, but apparently Tab is disabled until you change the text, i.e., pressing Tab while on default does not trigger the plug.

ghost commented 4 years ago

I am able to jump without changing the default text if I use <C-right> instead of <tab>. Only when I try to go the mucomplete way the tab won't allow me jump.

ghost commented 4 years ago

@lifepillar I looked through ultisnips keymappings and found that when there is a default value for a placeholder, ultisnips changes the mode to SELECT. To jump to next placeholder then requires mapping <tab> in SELECT mode as well. I added the following in my configuration:

 snoremap <silent> <tab> <Esc>:call UltiSnips#ExpandSnippetOrJump()<cr>

And now I am able to jump from default value. Might be a good idea to include in the documentation. What say?