CZ8. SublimeText : Add Snippets

This post is part of a series starting with
https://rasor.wordpress.com/2016/01/23/mean-stack-preparing-workflow-on-windows/

In this post I will add snippets to SublimeText.

Snippets should be divided into folders, that has the same name as the syntax, so they appear in the right context.

  • Create snippet template with
    • Tools – New snippet…

Snippets without scope

WordPress snippets

WordPress-code.sublime-snippet.

The snippet is for posting souce code into WordPress.

The below snippet don’t show right in the browser.

You must replace “<“code with “[“code. And likewise for the rest of the <> brackets used with “code”.

<snippet>
 <content><![CDATA[
<code language="${1:javascript}">
	${2://content}
</code>
]]></content>
 <tabTrigger>wp</tabTrigger>
</snippet>
  • ctrl-s – “WordPress-code.sublime-snippet” -Save
  • To use: write “wp” ctrl-space

Snippets with scope

JavaScript snippets

SelfInvokingAnonymousFunction.sublime-snippet

<snippet>
<!-- From https://code.tutsplus.com/courses/perfect-workflow-in-sublime-text-2/lessons/your-first-snippet -->
<content><![CDATA[
(function() {
${1}
})();
]]></content>
<tabTrigger>siaf</tabTrigger>
</snippet>
  • ctrl-s – <make dir “JavaScript”> – goto \JavaScript\ – “SelfInvokingAnonymousFunction.sublime-snippet” -Save
  • To use: In .js write “siaf” ctrl-space

Thanks to NetTuts for the lesson.

The End.

One Comment

Add yours →

  1. The default snippet folder is:
    C:\Users\youruserid\AppData\Roaming\Sublime Text 3\Packages\User

    More info: http://sublimetext.info/docs/en/extensibility/snippets.html

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: