片段添加日期时间吗

片段添加日期时间吗

本文介绍了我可以为 sublime 片段添加日期时间吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个片段来添加文件注释,但我希望片段自动创建 DateTime.一个崇高的片段可以做到这一点吗?

I want to create a snippet that will add a file comment, but I want the snippet to create the DateTime automatically. Can a sublime snippet do that?

<snippet>
    <content><![CDATA[
/**
 * Author:      $1
 * DateTime:    $2
 * Description: $3
 */

]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>/header</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>source.css,source.js,source.php</scope>
</snippet>

推荐答案

工具 > 新插件

粘贴:

import datetime, getpass
import sublime, sublime_plugin
class AddDateCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.run_command("insert_snippet", { "contents": "%s" %  datetime.date.today().strftime("%d %B %Y (%A)") } )

class AddTimeCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.run_command("insert_snippet", { "contents": "%s" %  datetime.datetime.now().strftime("%H:%M") } )

另存为 ~/Library/Application Support/Sublime Text 2/Packages/User/add_date.py

Save it as ~/Library/Application Support/Sublime Text 2/Packages/User/add_date.py

然后,在 Preferences > Key Bindings - User 中,添加:

Then, in Preferences > Key Bindings - User , add:

{"keys": ["ctrl+shift+,"], "command": "add_date" },
{"keys": ["ctrl+shift+."], "command": "add_time" },

您可以根据自己的喜好自定义传递给 strftime 的参数.

You can customize the argument passed to strftime to your liking.

这篇关于我可以为 sublime 片段添加日期时间吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 22:33