SublimeText3 snippet 编写总结

SublimeText的snippet定义功能也十分强大, 类似VAssist.

在菜单tool->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> -->
</snippet>

在 <content><![CDATA[  和  ]]></content>之前为要定义的内容块,

在 <tabTrigger>  与  </tabTrigger> 之间定义快捷名称,

在 <scope>  与  </scope> 之间定义该snippet作用的文件类型.

例如当需要输入html5这几个字符后按tab, 自动提示要输入的代码片段:
下面是我的html5 snippet

<snippet>
<content><![CDATA[
<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>${1}</title>
</head>
<body>
    <header>
        Hello, ${1:this} is a ${2:snippet}!
    </header>

<nav>${3:nav}</nav>

<article>
        <section>${4:section}</section>
    </article>

<aside>${5:aside}</aside>

<footer>${6:footer}</footer>
</body>
</html>
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>html5</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>index.html</scope>
</snippet>

编写好此文件后ctrl+s保存,此时会弹出默认的保存路径, 一般是..\Data\Packages\User下,

文件后缀名必须是.sublime-snippet。

我这里保存为html5.sublime-snippet或者您可以保存为其他的名称.

同一个snippet只能有一个。

${1}表示补全光标默认停留的位置, 编辑${1}完成后按tab可以跳转到${2}的位置,

this表示2处默认内容,完成${2}后,按tab之后会选中${3: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
CoffeeScript: source.coffee
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
LESS: source.css.less
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
SASS: source.sass
Scala: source.scala
Shell Script: source.shell
SQL: source.sql
Stylus: source.stylus
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

最新文章

  1. CSS3 Flexbox不迷路指南
  2. 公告栏放honehoneclock和喂小老鼠flash
  3. Hadoop阅读笔记(七)——代理模式
  4. 常见sql数据类型
  5. ASP.NET 中执行 URL 重写
  6. metro中stream转IRandomAccessStream
  7. ArcGIS AddIN开发异常之--修饰符“static”对该项无效
  8. Sky数[HDU2097]
  9. The Economist
  10. postconf 命令常用参数
  11. HDU4758 Walk Through Squares AC自动机&amp;&amp;dp
  12. Socket 服务器和客户端通信
  13. CentOS7 设置局域网固定IP
  14. datatables,表格
  15. 201521123075 《Java程序设计》第9周学习总结
  16. Spring(4)——面向切面编程(AOP模块)
  17. 【java】随机生成6位的数字
  18. I2C地址问题
  19. python使用pip下载模块
  20. presto .vs impala .vs HAWQ query engine

热门文章

  1. 编辑框的WM_MOUSELEAVE和WM_MOUSEHOVER使用
  2. IIS反向代理实现Revel域名访问
  3. 分享知识-快乐自己:IDEA 导入(web)项目并部署到 Tomcat
  4. EOF的使用
  5. &lt;十七&gt;UML核心视图动态视图之时序图
  6. 【C++ Primer 5th】Chapter 15
  7. css3渐变gradient
  8. POJ1287(最小生成树入门题)
  9. WPF访问UserControl的自定义属性和事件
  10. Linux下搭建tomcat集群全记录