zoukankan      html  css  js  c++  java
  • 自定义sublime代码片段

    sublime text 已经有一些他们内置的一些代码片段,但是有时候,这些并不能满足我们,这就需要我们自定义一些代码片段。

    步骤如下:

    1、打开sublime text

    2、选择 tools -> new snippet 就会打开一个未命名的文件,代码如下:

    <snippet>
      <content><![CDATA[
    Hello, ${1:this} is a ${2:snippet}.
    ]]></content>
      <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
      <!-- <tabTrigger>hello</tabTrigger> -->
      <!-- Optional: Set a scope to limit where the snippet will trigger -->
      <!-- <scope>source.python</scope> -->
     <!-- <description>my snippet</description> </snippet>

      解释如下:

      <![CDATA[ 和 ]]> 中间则是要输出的代码片段,中间的 ${1:this} 中的this是当前 ${1}位置默认用this,按tab键会切换到 ${2}处,依次类推。同一个 ${num}可以出现多次。

      tabTrigger 可选,触发该片段的字符串,比如下面用hello触发该片段,在页面输入hello按tab就会输出 <![CDATA[ 和 ]]> 中间的字符串

      scope 可选,设置该代码片段对什么类型的文件生效,不设置,则对所有类型生效。比如下面设置对html和js生效,在css下面输入 hello按tab不会有其他任何输出。过个代码片段用逗号(,)隔开。

      description 可选,设置该片段的说明,不定义,则显示文件名称。

    现在我们来创建一个自己的代码片段吧:

    <snippet>
         <content>
         <![CDATA[
         <footer>
              <p>Copyright © 2012 ${1:feige}.com</p>
              <p>增值电信业务经营许可证 赣A2-${2} <a href="#">赣ICP备号${3}</a></p>
         </footer>
         ]]>
         </content>
         <tabTrigger>cft</tabTrigger>
         <description>custom-footer</description>
         <scope>text.html,source.js</scope>
    </snippet>
    

      创建完毕以后,保存在PackagesUser目录下(例C:Users[用户]AppDataRoamingSublime Text 2PackagesUser),后缀名.sublime-snippet。

      重启sublime text 2,该snippet即可使用了。

    scope 列表:

    ActionScript: source.actionscript.2
    AppleScript: source.applescript
    ASP: source.asp
    Batch FIle: source.dosbatch
    C#: source.cs
    C++: source.c++
    Clojure: source.clojure
    CSS: source.css
    D: source.d
    Diff: source.diff
    Erlang: source.erlang
    Go: source.go
    GraphViz: source.dot
    Groovy: source.groovy
    Haskell: source.haskell
    HTML: text.html(.basic)
    JSP: text.html.jsp
    Java: source.java
    Java Properties: source.java-props
    Java Doc: text.html.javadoc
    JSON: source.json
    Javascript: source.js
    BibTex: source.bibtex
    Latex Log: text.log.latex
    Latex Memoir: text.tex.latex.memoir
    Latex: text.tex.latex
    TeX: text.tex
    Lisp: source.lisp
    Lua: source.lua
    MakeFile: source.makefile
    Markdown: text.html.markdown
    Multi Markdown: text.html.markdown.multimarkdown
    Matlab: source.matlab
    Objective-C: source.objc
    Objective-C++: source.objc++
    OCaml campl4: source.camlp4.ocaml
    OCaml: source.ocaml
    OCamllex: source.ocamllex
    Perl: source.perl
    PHP: source.php
    Regular Expression(python): source.regexp.python
    Python: source.python
    R Console: source.r-console
    R: source.r
    Ruby on Rails: source.ruby.rails
    Ruby HAML: text.haml
    SQL(Ruby): source.sql.ruby
    Regular Expression: source.regexp
    RestructuredText: text.restructuredtext
    Ruby: source.ruby
    Scala: source.scala
    Shell Script: source.shell
    SQL: source.sql
    TCL: source.tcl
    HTML(TCL): text.html.tcl
    Plain text: text.plain
    Textile: text.html.textile
    XML: text.xml
    XSL: text.xml.xsl
    YAML: source.yaml
    

      

  • 相关阅读:
    优先队列
    Problem W UVA 662 二十三 Fast Food
    UVA 607 二十二 Scheduling Lectures
    UVA 590 二十一 Always on the run
    UVA 442 二十 Matrix Chain Multiplication
    UVA 437 十九 The Tower of Babylon
    UVA 10254 十八 The Priest Mathematician
    UVA 10453 十七 Make Palindrome
    UVA 10163 十六 Storage Keepers
    UVA 1252 十五 Twenty Questions
  • 原文地址:https://www.cnblogs.com/ayseeing/p/4453956.html
Copyright © 2011-2022 走看看