2013-05-01 90 views
1

我为Sublime Text 2创建了很多片段。我总是使用可选的标签触发器,并且从不使用触发器范围。我想编辑“新摘录”模板,因此我不必每次都取消注释并删除这些相应的选项。如何在Sublime Text 2中编辑默认的'New Snippet'模板?

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> 

回答

4

新的片段命令在包中定义/默认/ new_templates.py 。在那里编辑它。 (我发现它在崇高打开Packages和寻找它的线路之一。

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

非常感谢,非常完美。 – 2013-05-01 23:44:28

+1

这将是聪明,使您的编辑到一个单独的插件,让你的变化不在更新中被删除,你可以在这里看到我是如何做到的:https://github.com/dsandstrom/CustomNewSnippet。我也为我的插件做了一个菜单项。 – 2013-05-09 20:14:05