多语言展示
当前在线:1367今日阅读:23今日分享:25

sublime 用snippet 创建文件头部信息

在sublime 编辑器创建一个snippet来快速创建头部信息
工具/原料

sublime

方法/步骤
1

在tool->developer->new snippet...创建一个新的snippet

2

在content标签里面编辑要在文件头部显示的信息,在tabTrigger标签中间编辑触发的单词--意思就是在文件头部输入单词,然后按tab键,会将content标签中间的信息显示出来;请看我的例子

3

其中有一个date time变量,snippet是不能自动创建时间的,需要你再创建一个插件,用来创建当前时间,步骤其实和创建snippet差不多,只不过需要选择的是new plugin,,然后将下面的代码粘贴到新的plugin文件里面:import datetime, getpassimport sublime, sublime_pluginclass AddDateTimeStampCommand(sublime_plugin.TextCommand):    def run(self, edit):        self.view.run_command('insert_snippet', { 'contents': '%s' %  datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') } )class AddDateStampCommand(sublime_plugin.TextCommand):    def run(self, edit):        self.view.run_command('insert_snippet', { 'contents': '%s' %  datetime.datetime.now().strftime('%Y-%m-%d') } )class AddTimeStampCommand(sublime_plugin.TextCommand):    def run(self, edit):        self.view.run_command('insert_snippet', { 'contents': '%s' %  datetime.datetime.now().strftime('%H:%M:%S') } )文件名字可以自己定义,保存的文件后缀是.py

4

虽然创建了plugin,但是还需要在sublime编辑器 用户按键--key bindings user文件里面编辑触发插件的快捷键代码:[    {'keys': ['ctrl+alt+shift+d'], 'command': 'add_date_time_stamp' },    {'keys': ['ctrl+alt+d'], 'command': 'add_date_stamp' },    {'keys': ['ctrl+alt+t'], 'command': 'add_time_stamp' }]

5

经过以上操作和编辑就可以了

推荐信息