gpt4 book ai didi

sublimetext2 - 我可以为 sublime 片段添加日期时间吗?

转载 作者:行者123 更新时间:2023-12-05 01:24:26 26 4
gpt4 key购买 nike

我想创建一个将添加文件注释的代码段,但我希望该代码段自动创建 DateTime。一个 Sublime 的片段可以做到这一点吗?

<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

然后,在 Preferences > Key Bindings - User 中,添加:
{"keys": ["ctrl+shift+,"], "command": "add_date" },
{"keys": ["ctrl+shift+."], "command": "add_time" },

您可以自定义传递给 strftime 的参数 to your liking .

关于sublimetext2 - 我可以为 sublime 片段添加日期时间吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11879481/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com