代码段(嵌套代码段)中选项卡函数的 ST3 交换优先级



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

例如,给定具有制表符触发器tabtrigA的代码段[ content A ${1:First point in A} and ${2: Second point in A} ]和具有制表符触发器tabtrigB的代码段[ content B ]

我希望能够执行以下操作:

在[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的优先级分配,使其首先充当选项卡触发器,并且仅在没有选项卡触发器时才跳转到下一个条目?


更新:截至 2019 年 4 月,仍然没有用于触发代码段内代码段的解决方案。

我不认为sublime可以从片段的next_field中分辨出这个片段的next_field。你只能问它是否has_next_field,有。但是您可以使用解决方法:


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

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

<snippet>
<content><![CDATA[
[ content B ]
]]></content>
<description>description_for_command_palette</description>
</snippet>
  1. 通过键绑定到代码段路径:

{ "keys": ["ctrl+0"], "command": "insert_snippet", "args": {"name": "Packages/User/your_snippet.sublime-snippet"}}

  1. 通过对匿名代码段的键绑定:

{ "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 }
]
}

最新更新