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.

Vivian De Smedt
  • 16,336
  • 3
  • 18
  • 37

1 Answers1

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
husB
  • 2,068
  • 5
  • 22
  • 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. – Maths Wizzard Mar 29 '22 at 09: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 '22 at 14:28
  • Hi, I have now marked the question as answered. I will link the other question in a second. – Maths Wizzard Mar 29 '22 at 17:31
  • 1
    Hi @husB, here is the link https://vi.stackexchange.com/questions/37111/vim-and-ultisnips-delay-with-pound-key – Maths Wizzard Mar 29 '22 at 17:37