很遗憾,片段选项卡触发器不能包含任何被 Sublime Text 视为单词分隔符的内容。
但是,如果您想将触发器文本保留在文档中,则可以使用键绑定来模拟此触发器:
{ "keys": ["tab"], "command": "insert_snippet", "args": { "name": "Packages/User/alter_aggregate.sublime-snippet" },
"context":
[
{ "key": "preceding_text", "operator": "regex_match", "operand": "\\bALTER AGGREGATE$", "match_all": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true },
{ "key": "selector", "operator": "equal", "operand": "source.sql", "match_all": true },
]
},
这假设您已将 sn-p 保存在您的 Packages/User 文件夹中,名称为 alter_aggregate.sublime-snippet。
示例 sn-p 内容(注意它缺少 ALTER AGGREGATE 但以空格开头:
<snippet>
<content><![CDATA[
${1:myavg(integer)} RENAME TO ${2:newname};
]]></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.sql</scope>
</snippet>
然后,输入 ALTER AGGREGATE Tab 会得到:
ALTER AGGREGATE myavg(integer) RENAME TO newname;
为方便起见,最初选择myavg(integer) 并按Tab 会将其移动到newname。