【问题标题】:In ST2 snippets, can $TM_CURRENT_WORD be overwritten?在 ST2 片段中,可以覆盖 $TM_CURRENT_WORD 吗?
【发布时间】:2013-05-06 10:27:51
【问题描述】:

对于上下文: 我正在为 Python 编写一个 sn-p 以快速转换变量,如下所示:variable_foostr(variable_foo)

如果我使用 $SELECTION,它可以正常工作。但如果我使用 $TM_CURRENT_WORD,它会将替换值插入到变量文本的中间,如下所示:variastr(variable_foo)ble_foo

我可以继续使用 $SELECTION,但我更希望不必先用 Ctrl+D 选择变量,这样 $ TM_CURRENT_WORD 会提供。有什么我忽略的东西使这成为可能,还是 $SELECTION 是唯一的方法?

供参考,sn-p的当前功能版本:${1:type}($SELECTION)${0}

还有一个替代版本:${1:type}${SELECTION/^.*/\($0\)/g}${0}

【问题讨论】:

    标签: sublimetext2 code-snippets


    【解决方案1】:

    我相信这是预期的行为。你可以使用插件来获得你想要的行为。

    import sublime_plugin
    
    class ExpandInsertSnippetCommand(sublime_plugin.TextCommand):
        def run(self, edit, contents=None, name=None):
            cursors = self.view.sel()
            new_cursors = []
            for cursor in cursors:
                new_cursors.append(self.view.word(cursor))
            cursors.clear()
            for cursor in new_cursors:
                cursors.add(cursor)
    
            self.view.run_command("insert_snippet", {"contents": contents, "name": name})
    

    不要对任何绑定使用命令“insert_sn-p”,而是使用“expand_insert_sn-p”。

    【讨论】:

      猜你喜欢
      • 2014-07-25
      • 2014-01-12
      • 1970-01-01
      • 2012-12-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 2022-08-18
      • 1970-01-01
      相关资源
      最近更新 更多