macOS sublime Text 3快速插入时间
【摘要】 安装插件
插件下载地址:https://github.com/kairyou/SublimeInsertDatetime
不同平台路径不一样,找到 Sublime Text安装目录,将insert_datetime.py放入Packages下就行
insert_datetime.py 源码备份,如果github打不开可以保存下面的代码
# coding=utf-...
安装插件
插件下载地址:https://github.com/kairyou/SublimeInsertDatetime
不同平台路径不一样,找到 Sublime Text安装目录,将insert_datetime.py
放入Packages下就行
insert_datetime.py 源码备份,如果github打不开可以保存下面的代码
# coding=utf-8
# 比较版本号
# import sys;print(sys.version_info[:2] < (3,0))
# import platform;print(platform.python_version() < '3.0')
# print(int(sublime.version()) < 3000)
import sys, sublime_plugin, datetime
class insertDatetimeCommand(sublime_plugin.TextCommand):
def run(self, edit, format): timestamp = datetime.datetime.now() if format == 'ymd': # yyyy-mm-dd timestamp = timestamp.strftime('%Y-%m-%d') elif format == 'ymdhms': # %X = %H:%M:%S timestamp = timestamp.strftime('%Y-%m-%d %X') else: # format == "xxx" # 2012-02-18 13:17:28.047000 #timestamp = datetime.datetime.now().isoformat(' ') # Sat Feb 18 13:20:41 2012 #timestamp = datetime.datetime.now().ctime() # 数字变为字符串 str(xx),字符串变为数字 int(string) timestamp = int(timestamp.strftime("%w")) week = { 1 : '一', 2 : '二', 3 : '三', 4 : '四', 5 : '五', 6 : '六', 7 : '日' } timestamp = '星期' + week[timestamp] # print(sys.version_info[:2] < (3,0)) if sys.version_info[:2] < (3,0): ## 中文要指定: coding=utf-8 | gbk ,再decode timestamp = timestamp.decode('utf-8') # else: # timestamp = timestamp.encode('utf-8').decode('utf-8') #for region in the selection for r in self.view.sel(): #put in the timestamp #(if text is selected, it'll be replaced in an intuitive fashion) self.view.erase(edit, r) self.view.insert(edit, r.begin(), timestamp)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
设置快捷键
快捷键绑定Preference → Key Bindings - User
[ { "keys": ["f5"], "command": "insert_datetime", "args": {"format": "ymd"} }, { "keys": ["alt+f5"], "command": "insert_datetime", "args": {"format": "ymdhms"} }, { "keys": ["ctrl+f5"], "command": "insert_datetime", "args": {"format": "E"} }
]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
重启生效
时间格式:
yyyy-MM-dd: F5
yyyy-MM-dd hh:mm:ss: alt+F5
星期E: ctrl+F5
- 1
- 2
- 3
参考
文章来源: pengshiyu.blog.csdn.net,作者:彭世瑜,版权归原作者所有,如需转载,请联系作者。
原文链接:pengshiyu.blog.csdn.net/article/details/80264168
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)