片段中的标签功能的ST3交换优先级(嵌套片段)

时间:2017-04-22 19:03:34

标签: tabs sublimetext3 code-snippets

发现自己经常在一个片段中调用一个片段,当然,当我去扩展嵌套片段时,tab键会将我移动到第一个片段的下一个条目或第一个片段的末尾(此时,我必须替换第二个片段和命中选项卡的tab触发器表达式末尾的光标,此时第二个片段被展开)。

例如。给定了代码段[ content A ${1:First point in A} and ${2: Second point in A} ],其中包含标签触发器tabtrigA和代码段[ content B ],其中包含标签触发器tabtrigB

我希望能够做到以下几点:

在[1]:

tabtrigA % Hit tab to expand snippet A

输出[1]:

 [ content **A First point in A** and ${2: Second point in A} ] % where everything between ** ** is highlighted

现在将**...**内容替换为tabtrigB

在[2]:

     [ content tabtrigB* and ${2: Second point in A} ] % where * marks location of cursor.

并点击tab会导致:

输出[2]:

 [ content [ content B ]* and ${2: Second point in A} ] % where * marks location of cursor

再次点击tab然后会跳转到代码段A的第二个条目

显然这很烦人:是否可以切换tab的优先级分配,使其首先作为制表符触发器,如果​​没有制表符触发器,则只跳转到下一个条目? / strong>

更新:截至2019年4月,仍无法触发代码段中的代码段。

1 个答案:

答案 0 :(得分:2)

我不认为崇高可以告诉这个片段' 那个片段的next_field的next_field。您只能询问是否has_next_field,any。但是你可以选择解决方法:

使用除TAB以外的其他内容触发嵌套代码段:

  1. 通过为您的嵌套代码段command palette提供description。下面的代码段可以从调色板中调用为代码段:description_for_command_palette

  2. <snippet>
    <content><![CDATA[
    [ content B ]
    ]]></content>
    <description>description_for_command_palette</description>
    </snippet>
    
    1. 通过键绑定到代码段路径:
    2. { "keys": ["ctrl+0"], "command": "insert_snippet", "args": {"name": "Packages/User/your_snippet.sublime-snippet"}}

      1. 通过对匿名片段的键绑定:
      2. { "keys": ["ctrl+0"], "command": "insert_snippet", "args": {"contents": "[ content B ]"}}

        覆盖密钥绑定以转到代码段中的下一个字段,例如输入。

        只需添加两个键绑定:

        { "keys": ["enter"], "command": "next_field", "context":
        [
        { "key": "has_next_field", "operator": "equal", "operand": true }
        ]
        },
        { "keys": ["tab"], "command": "insert_best_completion", "args": {"default": "\t", "exact": false}, "context":
        [
        { "key": "has_next_field", "operator": "equal", "operand": true }
        ]
        }