您可以创建一个自定义.sublime-completions http://docs.sublimetext.info/en/latest/reference/completions.html为此归档。在 Sublime 中使用 JSON 语法创建一个新文件,使用以下内容(当然可以根据您的需要进行定制):
{
"scope": "text.html - source, punctuation.definition.tag.begin",
"completions":
[
{ "trigger": "foo", "contents": "<foo>$0</foo>" },
{ "trigger": "bar", "contents": "<bar class=\"$1\">$0</bar>" },
{ "trigger": "baz", "contents": "<baz class=\"${1:myclass}\">$0</baz>" }
]
}
In the first example, typing foo
and hitting Tab will insert <foo>|</foo>
where |
is the cursor position.
In the second example, typing bar
and hitting Tab will insert <bar class="|"></bar>
. The cursor will first be between the quotes following class=
so you can enter your own class. Hitting Tab again will place the cursor just before </bar>
.
The third example works just like the second, except that the class
now has a default value. This value will be highlighted after typing baz
and hitting Tab - you can either hit Tab again to keep the default value and move the cursor between the opening and closing tags, or you can enter your own value, hit Tab, and move the cursor to between the opening and closing tags.
一旦你按照你喜欢的方式设置了所有内容,将文件另存为Packages/User/HTML.sublime-completions
, where Packages
是您选择时打开的文件夹Preferences -> Browse Packages...
.
欲了解更多信息,请点击上面的链接。要了解有关占位符和变量的更多信息,请查看本文档 http://docs.sublimetext.info/en/latest/reference/snippets.html.
祝你好运!