【问题标题】:ST3 swap priority of tab function within a snippet (nested snippets)ST3 在片段(嵌套片段)中交换选项卡功能的优先级
【发布时间】:2019-04-25 21:25:26
【问题描述】:

发现自己经常在一个 sn-p 中调用一个 sn-p,但是当我去扩展嵌套的 sn-p 时,tab 键将我移动到第一个 sn-p 的下一个条目或末尾第一个 sn-p (此时,我必须替换第二个 sn-p 的制表符触发表达式末尾的光标并点击制表符,此时第二个 sn-p 被扩展)。

例如。给定 sn-p [ content A ${1:First point in A} and ${2: Second point in A} ] with tab-trigger tabtrigA 和 sn-p [ content B ] with tab-trigger 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会跳转到sn-p A的第二个入口

显然这很烦人:是否可以切换tab的优先级分配,使其首先充当制表符,只有在没有制表符的情况下才跳转到下一个条目?


更新:截至 2019 年 4 月,仍然没有在 sn-p 中触发 sn-p 的解决方案。

【问题讨论】:

  • 您是否尝试过在您的用户首选项文件中设置"auto_complete_with_fields": true,
  • @KeithHall - 是的,这似乎并没有改变行为:它仍然跳转到 sn-p 中的下一个条目(或 sn-p 的末尾),而不是触发第二个sn-p。如果您有任何其他想法,请告诉我 - 在这个上搜索了一段时间,这真的很烦人!

标签: tabs sublimetext3 code-snippets


【解决方案1】:

我认为 sublime 无法从 that sn-p 的 next_field 中分辨出 this sn-ps' next_field。你只能问它是否有_next_field,任何。但是您可以使用解决方法:


用 TAB 以外的东西触发嵌套的 sn-p:

  1. 通过command palette 给嵌套的sn-p 一个description。下面的 sn-p 可作为 Snippet: description_for_command_palette 从调色板调用。


<snippet>
<content><![CDATA[
[ content B ]
]]></content>
<description>description_for_command_palette</description>
</snippet>
  1. 通过键绑定到 sn-p 路径:

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

  1. 通过与匿名 sn-p 的键绑定:

{ "keys": ["ctrl+0"], "command": "insert_snippet", "args": {"contents": "[ content B ]"}}


覆盖键绑定以转到 sn-p 中的下一个字段,例如输入。

只需添加两个键绑定:

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

【讨论】:

  • this question的答案在sn-p中只有一个field的情况下提供了另一种解决方案。简而言之,它通过使用${0:} 指定光标的退出位置来获得所需的结果。当然,这不适用于此处描述的情况。
猜你喜欢
  • 1970-01-01
  • 2013-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多