go to top

So you want to make a snippet in Sublime…

My friend and fellow info pro @archivalistic had a request: can you write up some documentation for creating snippets in Sublime that’s….readable? The answer is yes, yes I can. Here it is:

Snippets are fun for everyone!

Trust me, you really want to make these. It’ll make your life so much easier if you’re ever typing the same stuff oooover and over again (code, text, whatever you like!). Lorem ipsum filler text is a good example of this – it’s long by design, but there’s no way you’re going to remember the text, and it would be great if you didn’t even have to copy paste the text each time. Snippets can solve this for you.

How to Create a Snippet

Open up Sublime. Go to Tools > New Snippet. This will create a new document for you that should look like this:


You’re going to type the content you want a shortcut to where it says “Hello, ${1:this} is a ${2:snippet}.” So, for example, if I type “Emily Porta is the greatest web developer in the multiverse.” ALL the time, I could create a snippet for it by copying and pasting, or just writing, that text where the Hello message is, like this:


Now you could stop here, save, and that would be it, but chances are you enjoy productivity. If that’s the case, lets go ahead and create a tab shortcut so that all you have to do to insert this text is type the shortcut and hit tab and it will write it for you!

So now, take the comment markup off of “tabTrigger>hello…etc.” and replace “hello” with something sensible that you’ll remember. In this case, I’ll use “greatest”. Here’s an example with my changes to the code applied:


Finally, save your work! Save it as a sensible name (whatever you chose as your tab text is a good idea). When you go to save, it should auto open in the right path, but just in case here’s an example showing the correct one:


Notice that I’m saving the snippet with the file extension: “.sublime-snippet” – it probably does that automatically but I do it anyway because it makes me feel secure and fancy.

And that’s it! Now you can test it out!

Testing your new snippet+shortcut

To test your new snippet and it’s shortcut, simply open up a new document in Sublime (cmmd or ctrl + n) and type in the tabTrigger name you gave it (“greatest” in my example), and then hit TAB. You should see the text populate! Congrats!

**** If this doesn’t work for you, that sucks, but fear not – it’s probably just another plugin interfering with the snippet. Try using the command palette instead by typing command+shift+p and start typing the name of your snippet (eg. greatest) or just “snippet”, and click on the one you want. ****

NOTE: I’m using Sublime3. I have no idea if it will be different for previous versions. Tweet at me if it’s different ’cause that’s a Learning Moment: @AgentEmily.

This entry was posted in Uncategorized. Bookmark the permalink.

Comments are closed.