Sublime Help - 日期时间插件、Snippet代码片段

AI 摘要: 该文档介绍了如何在Sublime Text中添加日期时间插件,并提供了一些相关资料

1. 日期时间插件

1.1. 添加插件

新建插件:Tools > Developer > New Plugin... :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import sublime
import sublime_plugin
import time
import datetime
class insert_datetimeCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        week  = ['星期天','星期一', '星期二', '星期三', '星期四', '星期五','星期六',]
        weekdayShow    = week[datetime.datetime.today().weekday()]
        strShow = time.strftime("%Y-%m-%d %H:%M ") + weekdayShow
        self.view.run_command("insert_snippet", {
            "contents": "%s" % strShow
    })

1.2. 添加快捷键

配置快捷键:Sublime Text=> Perference=> Key Binds,绑定⌘+F1插入时间!

1
2
3
[
    {"keys": ["command+f1"], "command": "add_date_time" },
]

2. 代码片段 - Snippet

可以指定在特定文件中,快速插入一段自定义的代码!

比如插入特定宽度的img标签:

2.1. 添加方式

新建 Snippets:Tools > Developer > New Snippet,确定范围是在 Markdown 文件中触发,触发条件是输入tkimg900,编辑保存!

1
2
3
4
5
6
7
8
<snippet>
    <content><![CDATA[<img src="" width="900" />]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>tkimg900</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>text.html.markdown</scope>
    <description>Blog image 900 width</description>
</snippet>

3. 资料