Sublime Text 自定义 snippet

“snippet”在英语里面是“片段”的意思。当我们编码时候,通常想要打几个简略的字符串,就出来一些固定的模板,这个就类似于前端的zen coding。

不过,目前,sublime text2 的zen coding 不支持了,不知道sublime自己内置了什么默认的sinppet,只能实现一些简单的类似zen coding的功能。

定义很简单,先通过tools->new snippets就进入了新建文件。

文件包括以下内容:

<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

现在对以上的参数进行说明:

  • content:是你要定义的模板内容
  • tabTrigger:是你按tab键之前需要输入的快捷字符串,输了该字符串后,按tab键,就能生成你需要的模板内容啦
  • scope:是对文件格式的限制,比如,html格式的要设置为text.html

php示例code如下:

<snippet>

<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>

然后,保存文件,重命名为ej.sublime-smippet 代码中输入ej回车后就能显示出如下代码了:

echo json_encode($this);exit(1);

这里要注意的是scope,因为你不知道如何设置,才会让sinppet正常响应。设置出错,自然是无效啦。

列出scope列表,参考自:https://gist.github.com/iambibhas/4705378

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

转载于:https://www.cnblogs.com/lianche/p/4218174.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值