2

I have a snippet for C-like languages that looks like this:

snippet { "braces"
{
    $0
}
endsnippet

I would like to restrict this snippet to expand only if the tab trigger occurs at the end of the line.

I tried to use a regex trigger instead ({$) without success. To quote the documentation: "The snippet is expanded if the recently typed characters match the regular expression".

1
  • A regex snippet will not work because "The snippet is expanded if the recently typed characters match the regular expression." So it will always match /{$/ even if it's in the middle of the line...
    – filbranden
    Commented May 1, 2020 at 12:07

1 Answer 1

2

Nevermind, I figured out how to implement it as a custom context snippet:

snippet { "braces" "snip.column == len(snip.buffer[snip.line]) - 1" e
{
    $0
}
endsnippet

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.