How to edit the default 'New Snippet' template in Sublime Text 2?

喜欢而已 提交于 2019-12-11 10:50:48

问题


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 - Where does this default 'New Snippet' text come from so I can change it:

<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>

回答1:


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>
"""


来源:https://stackoverflow.com/questions/16325001/how-to-edit-the-default-new-snippet-template-in-sublime-text-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!