1

I have the following snippet

context "math()"
snippet `v([a-zA-Z]) ` "bb" A
``rv = '\\mathbf{' + m[1] + '}'`` 
endsnippet

Now, most of my snippets work, however, snippets with regex that ends with space do not exectute properly. When writing va + space, I get va instead of \mathbf{a}. I previously used hypersnips in vscode, for which this code worked. Does anyone know where is the issue?

NB: Any input of the form 'text*space*' doesn't seem to be recognized when written as 'text ' in the snippet section.

1 Answer 1

1

There are several issues with the syntax. Though HyperSnips is inspired by UltiSnips, there are notable differences between them. In particular,

  • For regex snippets, you need to specify the r flag
  • There are various forms of interpolation (shell, python, vim) in Ultisnips. The most flexible of these is python interpolation, which allows access to regex match groups (and a host of other things)
  • For python interpolation, use `!p ...` in place of `...`, and
  • snip.rv in place of rv
  • match groups are accessible with match.group()

For more, see

  • :h UltiSnips-snippet-options
  • :h UltiSnips-python
4
  • Hi, thank you for the comment. I have now managed to get the snippets running. Do you by any chance know how can I disable the # functionality? Whenever I have in a snippet it has a delay, taht is, when I type test#, the cursor moves infront of the pound key, waits one second, and then executes. Mar 29, 2022 at 9:02
  • @MathsWizzard Welcome to the site! Glad you got the snippets running :) If this answered your question, feel free to mark it as an answer. Alternatively, you may answer your own question. Regarding the other question, I guess that there is an insert mode mapping containing #. Could you ask a separate question for that?
    – husB
    Mar 29, 2022 at 14:28
  • Hi, I have now marked the question as answered. I will link the other question in a second. Mar 29, 2022 at 17:31
  • 1
    Hi @husB, here is the link vi.stackexchange.com/questions/37111/… Mar 29, 2022 at 17:37

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.