Suppose I have a snippet:

snippet prg 
    !This is file : `!v expand('%:t:r')`
    ! Author= `!v expand($USER)`
    ! Started at: `date +%d.%m.%y`
    ! Last Modified : Sun 16 Jun 2019 12:30:58 IST
    Program  ${1:<++`!v expand('%:t:r')`}
    Implicit None
    End Program  ${1/([^\n$]+).*/$1/}

and in vimrc, i have: let g:UltiSnipsExpandTrigger="<c-a>"

which is working fine.

Now, besides this, I am trying to have a keymap, like say, "prg in insertmode, which will expand this snippet for me. eg:

inoremap "prg :some_magic_(expand_snippet_prg)

any idea how to do this?

1 Answer 1


Use remap to trigger expansion

imap "prg prg<c-a>


exe printf('imap "prg prg%s',  g:UltiSnipsExpandTrigger)

But not this:

imap <expr> "prg 'prg' . g:UltiSnipsExpandTrigger

g:UltiSnipsExpandTrigger is a variable, map won't figure out special key code of it's value for you.

Manual expansion

inoremap "prg prg<c-r>=UltiSnips#ExpandSnippet()<cr>

You can't use <expr> here, as <expr> can't change buffer text.

You dont need to call expand on enviroment variable, $USER is enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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