Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I insert current time into a file using vim

Tags:

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)

EDIT

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

that was 30 minutes well spent vlog

and my log entry goes:

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

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>

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

like image 448
Cups Avatar asked Jun 14 '11 14:06

Cups


People also ask

What command will insert the current date into the file you are editing in vim?

In vim you can execute comands with "!". You can combine that with "r" to insert the output into your current buffer. will insert the date into a file.

How to insert date in Vim?

Now, anytime you want to insert a Markdown-style header with the current date and time, just press <leader>D (the default leader key in Vim is \ ). A new line with the current date and time, formatted per the strftime format, will be inserted below — great for note-taking or journaling.


1 Answers

I prefer to set an abbreviation for this like:

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

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.

like image 127
abcd Avatar answered Oct 22 '22 10:10

abcd