Fork me on GitHub

codeSnippet

利用代码段提高代码效率(sublime为例)

新建XXX.sublime-snippet文件

在tools中 选择 new snippet

保存 名称

代码段路径在 ..\Sublime Text 3\Packages\User 中,可以直接拷贝配置好的代码段使用

配置代码段

1
2
3
4
5
6
7
8
9
10
11
12
13
<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>

CDATA里面的${1:XXX} 表示执行代码后鼠标的位置
XXX表示默认值,
注意:如果我们在代码段里面要使用jQuery的$需要转义一下
这样使用\$

快速引用jQuery

在上目录新建jquery.sublime-snippet文件,
可以新建多目录文件管理snippet

1
2
3
4
5
6
7
8
9
<snippet>
<content><![CDATA[
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js"></script>
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>jqueryCdn</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.js</scope> -->
</snippet>

现在就很方便引入jquery了。
enter description here

ps: 常用scope列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Javascript: source.js
CSS: source.css
HTML: text.html(.basic)
JSON: source.json
HTML(TCL): text.html.tcl
Markdown: text.html.markdown
ActionScript: source.actionscript.2
AppleScript: source.applescript
ASP: source.asp
Batch FIle: source.dosbatch
C#: source.cs
C++: source.c++
Clojure: source.clojure
D: source.d
Diff: source.diff
Erlang: source.erlang
Go: source.go
GraphViz: source.dot
Groovy: source.groovy
Haskell: source.haskell
JSP: text.html.jsp
Java: source.java
Java Properties: source.java-props
Java Doc: text.html.javadoc
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
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
Plain text: text.plain
Textile: text.html.textile
XML: text.xml
XSL: text.xml.xsl
YAML: source.yaml

本文地址 http://xiaoqiang730730.github.io/2016/05/13/codeSnippet/

觉得有点意思,打个赏鼓励博主继续写哈!がんばって
前端-小强 WeChat Pay

微信打赏

前端-小强 Alipay

支付宝打赏