
r-斯坦解釋如何根據特定於文件類別(例如投影機或文章)的上下文定義鍵綁定。你怎麼能對一個片段做同樣的事情?
微量元素:
<snippet>
<content><![CDATA[
\alert{$1} $0
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>test</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>latextools.documentclass.article</scope>
</snippet>
答案1
您不能為片段編寫任意上下文,而只能編寫範圍。因此您無法為此建立程式碼片段。但是,您可以透過為鍵建立鍵綁定來模擬程式碼片段行為tab
,只有當插入符號之前的文字為 時才會觸發該鍵綁定test
。此鍵綁定應刪除其前面的單字並插入片段。如果你安裝了「Chain Of Command」包,你就可以使用這個鍵綁定:
{
"keys": ["tab"],
"command": "chain",
"args": {"commands": [
["delete_word", {"forward": false}],
["insert_snippet", {"contents": "\\alert{$1} "}],
]},
"context":
[
{ "key": "selector", "operand": "text.tex.latex" },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\btest$", "match_all": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "latextools.documentclass", "operand": "article" },
]
},
您可以透過將正規表示式變更"operand": "\\btest$",
為來調整它"operand": "\\byour_trigger$",