上下文定义的片段

上下文定义的片段

r-stein解释了如何根据特定于文档类的上下文(例如 beamer 或 article)定义键绑定。如何对片段执行相同操作?

梅威瑟:

<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$",

相关内容