发现自己经常在一个片段中调用一个片段,当然,当我去扩展嵌套片段时,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月,仍无法触发代码段中的代码段。
答案 0 :(得分:2)
我不认为崇高可以告诉这个片段' 那个片段的next_field的next_field。您只能询问是否has_next_field,any。但是你可以选择解决方法:
command palette
提供description
。下面的代码段可以从调色板中调用为代码段:description_for_command_palette 。
<snippet>
<content><![CDATA[
[ content B ]
]]></content>
<description>description_for_command_palette</description>
</snippet>
{ "keys": ["ctrl+0"], "command": "insert_snippet", "args": {"name": "Packages/User/your_snippet.sublime-snippet"}}
{ "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 }
]
}