1

I stole Gilles Castel's snippet for automatic subscript, and I tried to extend it to automatically subscript an i or j that follows any character. Here is my attempt

snippet '([A-Za-z])(?:\d|[ij])' "auto subscript" wrA
`!p snip.rv = match.group(1)`_`!p snip.rv = match.group(2)`
endsnippet

This throws

IndexError: no such group
Executed snippet code: 
  1 > snip.rv = match.group(2)
  2

I do not know any Python, but I am hoping that this isn't a very tricky issue to solve. Any help is appreciated. Thank you.

1 Answer 1

1

I believe the (?:...) makes the second sub-expression anonymous (you can't grab it with match.group).

I would try:

snippet '([A-Za-z])(\d|[ij])' "auto subscript" wrA
`!p snip.rv = match.group(1)`_`!p snip.rv = match.group(2)`
endsnippet
3
  • Yes, that works exactly as hoped. Thank you. Feb 18 at 15:30
  • 1
    Thanks for the feedback :-) If the solution works don't forgetting to validate it using v button next to the arrow voting buttons such that it can rest ;-) Feb 18 at 15:41
  • 1
    This broke my green tick and upvote virginity! Feb 18 at 19:10

Your Answer

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

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