Hammer. Wang
Hammer. Wang

Reputation: 714

How to add customized tags quickly in Sublime text 2?

Sorry for the newbie question. I'm using multiple times of the same tag with the same class, for example:

<p class = "paragraph_1"></p>

I'm just wondering how to add this same tag quickly in Sublime Text 2? I know the default tags can be added quickly by just typing a part of them and hit Tab. Is there any similar convenient way for those tags customized by myself?

Thank you very much!

Upvotes: 0

Views: 100

Answers (1)

r-stein
r-stein

Reputation: 4847

The Sublime Text HTML package inserts snippets into the completion system. If you also want to have your tags, you can just write a snippet for each tag.

To create a snippet:

  1. Open your User directory
    1. Click on Preferences
    2. then on Browse Packages...
    3. Open the directory User
  2. Create a file snippet_name.sublime-snippet
  3. Paste this into your snippet and change the content as you want:
<snippet>
  <!-- Example: Hello, ${1:this} is a ${2:snippet}. -->
  <content><![CDATA[
<p class="paragraph_1">$0</p>
]]></content>
  <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
  <tabTrigger>par1</tabTrigger>
  <description>Tag</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope>text.html.basic</scope>
</snippet>

However using SnippetMaker you can easily shorten the process. Just select the content, press ctrl+shift+p and write SnippetMaker: Make Snippet.

Additional remarks:

  • You can remove the snippet by removing the file.
  • The position of $0 marks cursor position at the end of the snippet.

Upvotes: 1

Related Questions