使用 Sublime Text 进行写作的时候, 难免会遇到需要重复输入的内容, 那么就可以使用内容片段(Snippet)来实现.
新建编辑内容片段: Tools(工具) -> Developer(开发者..) -> New Snippet…(新建片段…)
此时会出现如下内容:
1 | <snippet> |
content: 其中必须包含 <![CDATA[…]]>, 否则无法工作, 修改 Hello, ${1:this} is a ${2:snippet}. 部分, 用来写你自己的内容片段
tabTrigger: 用来引发内容片段的字符或者字符串, 比如在以上例子上, 在编辑窗口输入 hello 然后按下 tab 就会在编辑器输出 Hello, ${1:this} is a ${2:snippet}. 这段内容
scope: 表示你的代码片段会在那种语言环境下激活, 比如上面代码定义了 source.python, 意思是这段代码片段会在 python 语言环境下激活.
description: 展示代码片段的描述, 如果不写的话, 默认使用代码片段的文件名作为描述
content 的使用
1 | <snippet> |
其中 ${1:Author} 等为站位符号, 表示生成之后可以按 tab 键跳转到该符号位进行再编辑.
tabTrigger 快捷键
将上面的内容保存为 bq.sublime-snippet 文件, 存档到 Sublime Text/Packages/User/ 目录下, 在 markdown(*.md)文件下, 输入 bq 之后按 tab 键就可以生成如下内容:
1 | {% blockquote Author, Source Link SourceTitle %} |
这一部分详细阅读手把手教你写 Sublime 中的 Snippet
scope 有效文件类型
接下来如果要配置不同类型文件有效, 那么就要使用到 scope 属性:
| 语言(语法) | Scope 名称 |
|---|---|
| ActionScript | source.actionscript.2 |
| ActionScript 3 | source.actionscript.3 |
| Ant | text.xml.ant |
| AppleScript | source.applescript |
| ASP | source.asp |
| Batch File | source.dosbatch |
| Bibtex | text.bibtex |
| C | source.c |
| C# | source.cs |
| C++ | source.c++ |
| camlp4 | source.camlp4.ocaml |
| Clojure | source.clojure |
| CoffeeScript | source.coffee |
| CSS | source.css |
| D | source.d |
| Diff | source.diff |
| DOT | source.dot |
| Emmet | source.zen.5a454e6772616d6d6172 |
| Erlang | source.erlang |
| Go | source.go |
| Groovy | source.groovy |
| Haskell | source.haskell |
| Hex | source.hex |
| HTML | text.html.basic |
| HTML (ASP) | text.html.asp |
| HTML (Erlang) | text.html.erlang.yaws |
| HTML (Rails) | text.html.ruby |
| HTML (Tcl) | text.html.tcl |
| HTML5 | text.html.basic |
| Java | source.java |
| Java Server Pages (JSP) | text.html.jsp |
| JavaDoc | text.html.javadoc |
| JavaProperties | source.java-props |
| JavaScript | source.js |
| JavaScript (Rails) | source.js.rails |
| jQuery (JavaScript) | source.js.jquery |
| JSON | source.json |
| LaTeX | text.tex.latex |
| LaTeX Beamer | text.tex.latex.beamer |
| LaTeX Log | text.log.latex |
| LaTeX Memoir | text.tex.latex.memoir |
| Lisp | source.lisp |
| Literate Haskell | text.tex.latex.haskell |
| Lua | source.lua |
| Makefile | source.makefile |
| Markdown | text.html.markdown |
| Matlab | source.matlab |
| MultiMarkdown | text.html.markdown.multimarkdown |
| MXML | text.xml.mxml |
| NAnt Build File | source.nant-build |
| Objective-C | source.objc |
| Objective-C++ | source.objc++ |
| OCaml | source.ocaml |
| OCamllex | source.ocamllex |
| OCamlyacc | source.ocamlyacc |
| Perl | source.perl |
| PHP | source.php |
| Plain text | text.plain |
| Python | source.python |
| R | source.r |
| R Console | source.r-console |
| Rd (R Documentation) | text.tex.latex.rd |
| RegExp | source.regexp |
| Regular Expressions (Python) | source.regexp.python |
| reStructuredText | text.restructuredtext |
| Ruby | source.ruby |
| Ruby Haml | text.haml |
| Ruby on Rails | source.ruby.rails |
| Scala | source.scala |
| SFTP Output Panel | output.sftp |
| Shell Script (Bash) | source.shell |
| SQL | source.sql |
| SQL (Rails) | source.sql.ruby |
| Tasks | text.todo |
| Tcl | source.tcl |
| TeX | text.tex |
| TeX Math | text.tex.math |
| Textile | text.html.textile |
| XML | text.xml |
| XSL | text.xml.xsl |
| YAML | source.yaml |
这一部分详见Sublime Text 2 中怎样查找 scope 的名称
description 描述
用于描述一下这个片段的大致内容, 概要