Sublime Text 2 custom code snippet

Source: Internet
Author: User
Tags cdata

This article refers to http://www.blogjava.net/Hafeyang/archive/2012/08/17/how_to_create_code_snippet_in_subline_text_2.html

For front-end engineers, the basic structure of writing an HTML page is manual work, and every time you copy a problem, sublime text 2 provides a good code snippet for reuse. The procedure for creating a HTML5 code fragment is described below.

On the menu, click Tools, New Snippet, (Tools---code snippet) to create a new XML File tab:

<snippet>
<content><! [cdata[
Hello, ${1:this} is a ${2:snippet}.
]]></content>
<!--Optional:set a tabtrigger to define what to trigger the snippet-
<!--<tabTrigger>hello</tabTrigger>--
<!--Optional:set a scope to limit where the snippet would trigger--
<!--<scope>source.python</scope>--
</snippet>


The comments have been described in more detail.

Content inside is the code template: ${Sequence Number: The default value}, the same number of places the cursor will be stopped at the same time can be edited in many places. The ordinal size is tabindex. When you actually use the code, you can use tab to toggle the cursor position.

Tabtrigger is when you enter the string and the tab is the content of the cursor that is inserted in content.

Scope refers to which file types are used.

Here is the definition of the HTML5 code fragment:

<snippet>
<content><! [cdata[
<!doctype html>
<meta charset= "Utf-8" >
<title>${1}</title>
<body>
Hello, ${2:this} is a ${3:snippet}.
</body>
]]></content>
<!--Optional:set a tabtrigger to define what to trigger the snippet-
<tabTrigger>html5</tabTrigger>
<!--Optional:set a scope to limit where the snippet would trigger--
<!--<scope>source.python</scope>--
</snippet>


Save the default save path as c:\users\[user]\appdata\roaming\sublime Text 2\packages\user\html5.sublime-snippet (Win7) after editing is done. The suffix must be. Sublime-snippet.

After you save the restart Sublime Text 2, create a new file: Enter Html5,tab The following effect appears:



${1} appears two times, so the cursor edits two of the graphs simultaneously.
${2:this}, the This default value appears at 2. ${1} at the end of the Edit press TAB to ${2}.

OK, that's all.

Sublime Text 2 custom code snippet

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.