Optional whitespace based on character after snippet trigger
I'm trying to make a snippet to create an html attribute and insert a space after it, if the next symbol isn't ">".
Usecase:
<div cl|> expands to:
<div class="|">
<div cl|id="foo"> expands to
<div class="|" id="foo">
So, basically, is there a way to get characters on the trigger line? If not python maybe VimL? (Get a linenumber of the line where trigger happened and read this line from the file defined in snip.fn?.. There should be an easier way.)
Also, workarounds I came up with:
1. Add a tabstop prepopulated with a single space (that can be removed):
snippet cl
class="$1"{2: }
endsnippet
2. Include the optional space to trigger regex:
snippet "cl(\s)?" "HTML class" r
class="$1"`!p snip.rv = match.group(1) if match.group(1) is not None else ""`
endsnippet
But, maybe there's a more elegant solution?
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- UltiSnips Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask mwgkgk for more information if necessary.