如何在sublime中使用快捷键添加当然时间
2015-04-09 16:13
351 查看
要实现快捷键,直接出现时间。
这里还是用到python写的插件,本身他也是python写的
编写python
# 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)
保存为insert_datetime.py。sublime安装文件夹
Sublime Text\Data\Packages\ 内
具体下载地址:https://github.com/kairyou/SublimeInsertDatetime
相关文章推荐
- sublime_text中如何使用快捷键打开默认浏览器
- sublime 代码片段如何加上当前时间,代码片段如何使用
- 我使用的sublime快捷键(持续添加) 和eclipse快捷键
- sublime右击快捷键如何添加
- centos6.5源码安装和centos7.2使用yum安装httpd后,如何添加模块;以及怎么设置Cache-Control:max-age=?浏览器缓存时间
- centos6.5源码安装和centos7.2使用yum安装httpd后,如何添加模块;以及怎么设置Cache-Control:max-age=?浏览器缓存时间
- 使用asp.net 2.0的CreateUserwizard控件如何向自己的数据表中添加数据
- j2me中如何使用Calendar获取系统时间并转换成字符串格式
- 如何使用 Visual Studio .NET 将 SQL Server 2000 存储过程添加到 Visual SourceSafe
- 如何使用 Visual Studio .NET 将 SQL Server 2000 存储过程添加到 Visual SourceSafe
- CP How-To:如何使用Cpanel添加Subdomains(子域名)
- 如何有效使用时间
- 如何延长手机电池使用时间(from:http://blog.163.com/sz.sn/blog/static/6250252006710410300/)
- asp中如何使用日期和时间
- 使用asp.net 2.0的CreateUserwizard控件如何向自己的数据表中添加数据
- 如何使用delphi实现取得开机时间
- 关于如何为FormView中的Richedit/Edit添加右键菜单,并响应CTRL+C等快捷键
- FormsAuthentication如何添加过期时间
- 如何通过使用注册项 (.reg) 文件添加、修改或删除注册表子项和值
- 使用asp.net 2.0的CreateUserwizard控件如何向自己的数据表中添加数据