I am trying to expand my snippets. I use Ultisnips.

ofcourse, I can have

snippet 'a "greek alpha" A


snippet 'A "greek alpha" A

and both works fine. But, I am looking for something like

snippet '[aA] "greek alpha" A

i.e. if I put 'a, I will get \alpha, with 'A, I will get \Alpha from same snippet. Is this possible?

1 Answer 1


Yes, it's possible to use parts of the snippet trigger in the output, but it's not as simple as using a matching character class on each side.

To correctly configure this, you need to use an r flag to use a regular expression in the trigger, use a capturing group inside parens for the character class (the trigger needs to be inside quotes as well.)

And then in the expansion you need to use a Python block and access the match object to get the contents of the capture group.

This snippet does it:

snippet "'([aA])" "greek alpha" rA
\\`!p snip.rv = match.group(1)`lpha
  • 1
    Ah! Much ado about a little thing. I will skip that.
    – BaRud
    Jan 29, 2021 at 15:18

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.