如何在Sublime Text 2中编辑默认的“ New Snippet”模板? [英] How to edit the default 'New Snippet' template in Sublime Text 2?

查看:176
本文介绍了如何在Sublime Text 2中编辑默认的“ New Snippet”模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Sublime Text 2创建了很多片段。我始终使用可选的Tab触发器,并且从不使用触发器范围。我想编辑 New Snippet模板,这样就不必每次都取消注释并删除这些选项。

I create a lot of snippets for Sublime Text 2. I always use the optional tab trigger and never use the trigger scope. I'd like to edit the 'New Snippet' template so I don't have to uncomment and delete these respective options every time.

TL; DR-默认的新代码段文本来自何处,因此我可以对其进行更改:

<snippet>
    <content><![CDATA[
Hello, ${1:this} is a ${2:snippet}.
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <!-- <tabTrigger>hello</tabTrigger> -->
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.python</scope> -->
</snippet>


推荐答案

新的代码段命令在 Packages中定义/Default/new_templates.py 。在那里编辑。 (我通过在崇高状态下打开包装并进行搜索找到了它

The new snippet command is defined in Packages/Default/new_templates.py. Edit it there. (I found it by opening Packages in sublime and searching for one of it's lines.

class NewSnippetCommand(sublime_plugin.WindowCommand):
    def run(self):
        v = self.window.new_file()
        v.settings().set('default_dir',
            os.path.join(sublime.packages_path(), 'User'))
        v.settings().set('default_extension', 'sublime-snippet')
        v.set_syntax_file('Packages/XML/XML.tmLanguage')

        template = """<snippet>
    <content><![CDATA[
Hello, \${1:this} is a \${2:snippet}.
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <!-- <tabTrigger>hello</tabTrigger> -->
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.python</scope> -->
</snippet>
"""

这篇关于如何在Sublime Text 2中编辑默认的“ New Snippet”模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆