“snippet”在英语里面是“片断”的意思。当咱们编码时候,一般想要打几个简略的字符串,就出来一些固定的模板,这个就相似于前端的zen coding。php
不过,目前,sublime text2 的zen coding 不支持了,不知道sublime本身内置了什么默认的sinppet,只能实现一些简单的相似zen coding的功能。css
定义很简单,先经过tools->new snippets就进入了新建文件。html
文件包括如下内容:前端
<snippet> <content><![CDATA[ ]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <tabTrigger></tabTrigger> <!-- Optional: Set a scope to limit where the snippet will trigger --> <scope></scope> </snippet
如今对以上的参数进行说明:java
php示例code以下:python
<content><![CDATA[
echo json_encode(${1:\$this});exit(${2:1});
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>ej</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.php</scope>
</snippet>git
而后,保存文件,重命名为ej.sublime-smippet 代码中输入ej回车后就能显示出以下代码了:github
echo json_encode($this);exit(1);
这里要注意的是scope,由于你不知道如何设置,才会让sinppet正常响应。设置出错,天然是无效啦。sql
列出scope列表,参考自:https://gist.github.com/iambibhas/4705378:shell
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