如何使用vim将当前时间插入到文件中 [英] How do I insert current time into a file using vim

查看:104
本文介绍了如何使用vim将当前时间插入到文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是一边做一边记录一些工作,每一行都是一个动作,我会每隔几分钟尝试一次.是否有插入日期/时间的技巧,例如:

I'm just logging some work as I do it, each line being an action, I will be trying to do this every few minutes. Is there a trick way of inserting date/time something like:

14 June 2011 15:01:00 Downloaded source code from GIT

会做的很好......虽然考虑一下,在我添加新行时插入日期可能也不错..

Would do fine... although thinking about it, inserting the date as I add a new line might be nice too..

也欢迎其他人在尝试实现类似目标时使用的任何其他快捷方式.

Any other shortcuts that anyone else uses when trying to achieve similar would also be welcome.

(Win32, vim6.4)

(Win32, vim6.4)

编辑

这是我最后的结果:我输入:附加vlog"然后一个空格,就像这样

Here is what I ended up with: I type: appending 'vlog' then a space, like so

that was 30 minutes well spent vlog

我的日志条目如下:

that was 30 minutes well spent 
Jun-14 16:50 

随着我准备好输入下一行,那就是 .vimrc (_vimrc) 条目:

With me ready to type the next line, thats with With the .vimrc (_vimrc) entry:

"use this for file logging 
:iab vlog <cr><c-r>=strftime("%b-%d %H:%M") <cr>

科尔!现在让我们回到 30 分钟......为回复干杯!

Cor! now lets get that 30 minutes back... cheers for the replies!

推荐答案

我更喜欢为此设置一个缩写,例如:

I prefer to set an abbreviation for this like:

iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>

所以当我输入 "Downloaded source code on xdate" 时,vim 会自动将 "xdate" 扩展为 "14/06/11 hrs:mins:秒".处于插入模式并且不必中断我的打字流程以进入正常模式或按快捷方式有时很有用.此外,如果您愿意,您可以将其设置为比 "xdate" 更短的组合.

So when I type "Downloaded source code on xdate", vim automatically expands the "xdate" to "14/06/11 hrs:mins:secs". Being in insert mode and not having to disrupt my flow of typing to either get into normal mode or press a shortcut is useful at times. Also, you can set it to a shorter combination than "xdate" if you so wish.

这篇关于如何使用vim将当前时间插入到文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆