Sublime Forum

Whether sublime-snippet files can contain multiple template rules

#1

Can only contain one template rule per sublime-snippet file?This makes me feel very troublesome. Is it possible to write multiple rules in one file?

0 Likes

#2

Not currently, No. You can define only one snippet per .sublime-snippet file. You can’t have multiple snippets in the same file. (Or it might be possible to save multiple in one file, but most likely it’ll just pick the first one, so the rest won’t be of use anyways)

0 Likes

#3

Note that if you want to put multiple completions into a single file, you can use a sublime-completions file for that.

Caveats here are that all completions in the file need to share the same scope, and the file format is JSON, which means more character quoting and that completions that expand out to multiple lines are more of a headache.

0 Likes

#4
  • Thank you. It does solve my problem
    However, there is a new problem. After I type source.js in the scope option, the result is that the script tag in the HTML can fire, but it cannot fire in the js file
0 Likes

#5

If I may point you in the direction of this post (which is 95% @OdatNurd and maybe I’ll claim 5%)

makes snippet creation a lot less painful.
@OdatNurd mentions that perhaps it’s over kill (my phrasing) using snippets when there’s sublime-completions, but I’d maintain that the "auto snippet function" means a lot less typing.

Plus you don’t have to remember what particular bits of code you want to “snippetise”; you code, think this needs a snippet, select text, press super+s twice (my keybinding) , the snippet comes up, maybe tweak, and save. Done in a second or two. Maybe five tops.

In the last post I’ve tweaked it specifically for C++ (I’m just starting to learn Python, if you know some, tweak on). I’m happy to help if I can…

It doesn’t sort your one file one snippet issue (which comes up occasionally on this forum, infact I think I’ve ased the same question before) but it does make snippets easier. (or so I’ve found)

Hope this helps… Loz

0 Likes