Aleski
Aleski

Reputation: 1442

Condense all my snippets into one file in Sublime Text 3

I have a multitude of snippets for each tag in the language I am currently programming in. I want to share these with some of my co-workers but I don't want to send them like 30 snippet files. Is there a way to condense these into one file (apart from zipping them, sending the zip and then having them unzip it).

Upvotes: 1

Views: 260

Answers (1)

MattDMo
MattDMo

Reputation: 102862

You can use a .sublime-completions file. These are JSON-formatted files that contain the target scope at the top, then a series of completions with a trigger and contents. For example, the following snippet

<snippet>
    <content><![CDATA[function ${1:function_name} (${2:argument}) {
    ${0:// body...}
}]]></content>
    <tabTrigger>fun</tabTrigger>
    <scope>source.js</scope>
    <description>Function</description>
</snippet>

can be turned into this completion:

{
    "scope": "source.js",

    "completions":
    [
        { "trigger": "fun", "contents": "function ${1:function_name} (${2:argument}) {\n    ${0:// body...}\n}" }
    ]
}

Use \n for newlines and \t for tab characters in the "contents" section. Double quotes need to be escaped as well. Also, you can use \t to separate the trigger from a brief description on what the completion is about, it will be displayed right-aligned and slightly grayed and does not affect the trigger itself:

{ "trigger": "fun\tFunction", "contents": "function ${1:function_name} (${2:argument}) {\n    ${0:// body...}\n}" }

Since this is JSON, to add multiple completions just put a comma , after the closing curly brace } of the completion, and put your next one on the next line. The final line should not have a final comma.

Good luck!

Upvotes: 3

Related Questions