1001Ferramentas
💎 Dev

Sublime Text Snippet Generator

Create a .sublime-snippet XML file with trigger, scope and content. Drop into Packages/User/ in Sublime.

A Sublime Text snippet in the XML it expects

A Sublime snippet is an XML file with four parts: the content to be inserted, the trigger typed before Tab, the scope where the snippet is available and the description shown in the menu. The format is simple, but it has escaping traps that produce a file the editor silently ignores, with no error message.

Fill in the fields and the page assembles the XML. The content goes inside a CDATA section, which is what lets you write code with angle brackets without escaping anything — and the page handles the one case that still breaks there, which is content containing the section's own closing sequence. The other fields are escaped normally.

Inside the content the editor's placeholders apply: a dollar sign followed by a number marks the cursor stops in order, and the braced form allows default text at each stop. Dollar zero marks where the cursor ends up. The scope is what prevents clutter: a JavaScript snippet declared with no scope starts appearing in plain text, configuration and Markdown files.

Frequently asked questions

Where do I save the file?
In the user packages folder, with the sublime-snippet extension. Any filename works — what identifies the snippet is the trigger, not the name. The editor reloads by itself on save, with no restart needed.
How do I find the right scope?
With the command that shows the scope under the cursor, available from the palette. It displays the full chain, and you choose the level of specificity — source.js covers all JavaScript, while deeper levels restrict to contexts such as inside a string or a comment.
Why does my snippet not trigger?
Almost always the wrong scope or a trigger clashing with another snippet. It is also worth checking the XML: if it is malformed, Sublime ignores the file silently, without warning — which is why correct escaping matters more here than in formats that complain.

Related Tools