【问题标题】:Create Key Binging in Sublime Text 2 that tags highlighted text with snippet在 Sublime Text 2 中创建键绑定,用片段标记突出显示的文本
【发布时间】:2016-01-06 00:58:27
【问题描述】:

我已经建立了一个sn-p。哪个工作正常。
为了更好地帮助理解问题,假设我的 sn-p 创建了一个具有内联样式的锚标记:

<a style="color:red;font-weight:30px;"></a>

我的问题是,当我尝试添加键绑定时,例如:

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

如果我选择突出显示的文本,然后单击 ctrl+a,它会删除文本并添加 sn-p。相反,我希望它将文本包装在 sn-p 中。如:

<a style="color:red;font-weight:30px;">HelloWorld</a>

有什么想法吗?
提前致谢!!

【问题讨论】:

    标签: sublimetext2 key-bindings code-snippets


    【解决方案1】:

    如果您查看documentation on snippets,您会看到有许多variables 可以访问,包括$SELECTION。所以,你的 sn-p 应该是:

    <snippet>
        <content><![CDATA[<a style="color:red;font-weight:30px;">$SELECTION</a>]]></content>
        <scope>text.html</scope>
    </snippet>
    

    【讨论】:

      猜你喜欢
      • 2014-10-14
      • 1970-01-01
      • 1970-01-01
      • 2013-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多