1

Is it possible to assign a key combination to a snippet in Ultisnip?

I tried something hacky like

nnoremap KEYKOMBO iULTISNIPTRIGGER<TAB>

but it doesn't trigger my snippet like it would, if I entered insert mode manually, then typed the Trigger-Word and pressed tab (which is the default Ultisnip keybinding for expanding).

1 Answer 1

3

From documentation on :nnoremap:

:no[remap]! {lhs} {rhs}

[…] Disallow mapping of {rhs}, to avoid nested and recursive mappings.

But the whole point of your mapping is to use recursive mapping of Tab! Use :nmap instead.


Alternatively, and even preferably, use the following:

nnoremap KEYCOMBO iULTISNIPTRIGGER <esc>:call UltiSnips#ExpandSnippet()<cr>

(note the space after the trigger.)

Calling the function directly is better than invoking it through a key mapping, as it is resilient to the changes in the mappings—later on, you might remap UltiSnips to another key, but KEYCOMBO will keep working for as long as you have UltiSnips installed.

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.