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
    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 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.