By josh / April 23, 2013

Using Sublime Text snippets to compose emails

Sublime Text’s snippets are a great productivity booster. If you’re not familiar with this feature, a snippet is a block of boilerplate code or text that you insert by typing a keyword and hitting the Tab key. For example, typing “lorem” (without the quotes) and pressing Tab will insert a block of lorem ipsum filler text. Snippets can also contain fields that allow you to quickly fill in the blanks to implement the code.

It’s easy to define custom snippets, which is useful if you want to define reusable code blocks to share with your team members. Or maybe you just want a way to quickly compose snarky replies to head hunters looking for candidates with at least 10 years of Ruby on Rails experience.

Creating a Sublime snippet is as simple as filling in a few values in a custom XML format and saving the file with a .sublime-snippet extension.

Each snippet file includes the word that triggers the snippet, a CDATA section for the content (more on this in a minute), a scope that indicates when the snippet should be available, and a description that appears when you invoke the snippet from the Command Palette.

The CDATA section is where the meat of your snippet goes. You can insert text or code as well as field markers that let the user hit Tab to jump through and edit sections of the snippet. You can also include placeholder text for each field.

To use your new snippet, just save the XML in your Packages/Users folder with a .sublime-snippet extension. Sublime will load it automatically—no need to restart the app. I have a snippets subfolder where I put all of my custom snippets to keep them organized.

For an empty snippet template as well as an example of a snippet that let’s you dish the snark to spammy recruiters, see https://gist.github.com/4182231.

P.S. If you’d like to learn more ways to improve your productivity with Sublime Text, sign up for the Sublime Text Tips weekly newletter:

http://sublimetexttips.com/newsletter

About the author

josh

Click here to add a comment

Leave a comment: