「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