【问题标题】:How does $TM_CURRENT_WORD operate in Sublime Text?$TM_CURRENT_WORD 在 Sublime Text 中如何操作?
【发布时间】:2016-12-02 06:37:45
【问题描述】:

在 Sublime Text 文档中,我看到 TM_CURRENT_WORD 的以下定义

$TM_CURRENT_WORD    Current word under the cursor when the snippet was triggered.

我对如何在实践中使用它感到困惑。光标下的单词不总是tabTrigger中的那个吗?我正在尝试使用此参数将参数传递给 Sublime sn-p 但无法使其正常运行。

【问题讨论】:

  • 您的困惑是基于这样的想法,即插入 sn-p 的唯一方法是通过选项卡触发器。但是,它们也可以通过键绑定或插件插入。
  • 感谢您告诉我。我找到了允许这样做的链接:stackoverflow.com/questions/15582210/…

标签: sublimetext


【解决方案1】:

这个 sn-p 对我来说很好用:

<snippet>
    <content><![CDATA[
Before you insert snippet cursor was in this "$TM_CURRENT_WORD" word.${0}
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>word</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>text</scope>
</snippet>

there你可以找到非常有趣的例子:

<snippet>
    <content><![CDATA[ = $TM_CURRENT_WORD + 1]]></content>
    <tabTrigger>++</tabTrigger>
    <description>i = i + 1</description>
    <scope>source.fortran</scope>
</snippet>

【讨论】:

  • 你知道,我查看了那个链接,似乎选项卡触发器是侥幸,因为他不能对 -- 做同样的事情:“事实上 a++ 对你有用更多的是运气而不是设计,因为出于某种原因,sublime 将 ++ 视为一个单独的“词”。但它几乎不会用于其他任何事情,除非在其他一些边缘情况下。”
  • @Abundance,您可以为 sn-p 绑定快捷方式,而不是使用问题 cmets 中描述的选项卡触发器
猜你喜欢
  • 2023-04-02
  • 2013-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-09
  • 2017-04-01
  • 2015-03-31
相关资源
最近更新 更多