Creating Basic Snippets in Sublime Text

Posted January 7, 2014 by Chris Luongo in Computer programming

By allowing you to create smart shortcuts when coding, snippets make coding less tedious.

Snippets are one of the coolest features in Sublime Text 2. Selecting from a library of predefined snippets of code makes life much easier when coding. Sublime has some snippets included by default, but you can easily create your own.

In this tutorial we will explore how snippets work and how you can create your own custom snippets.

1. Go to Tools -> New Snippet

Sublime Text Tools New Snippet

You will see a new file open with some skeleton XML in it

Sulbime Text Snippet 2

2. The content tags will hold what your snippet will print out. You would include your output within the the <![CDATA[ ]]> tag. For my example I put a simple HTML doctype as my snippet.


3. Next, we need to set a sequence of keys that will be bound to the snippet. In the tabTrigger tag, type what you want your sequence to be. I titled this one “doc2” for this example.


4. Go to File -> Save As to save your snippet. Now your ready to try it out.

5. When in a new document, type your trigger (‘doc2’ in our case) then hit the [tab] key.




About Chris Luongo

Chris is a self-taught web designer and developer out of Atlanta, GA. This geek enjoys coffee, cold brews, bike riding, and twisting any form of tech into submission.
View more articles by Chris Luongo

The Conversation

Follow the reactions below and share your own thoughts.