5

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!

Cups
  • 6,901
  • 3
  • 26
  • 30
  • 1
    Possible duplicate: http://stackoverflow.com/questions/56052/best-way-to-insert-timestamp-in-vim – tplaner Jun 14 '11 at 14:04

3 Answers3

11

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.

abcd
  • 41,765
  • 7
  • 81
  • 98
  • Thanks very much, sorry my search skills were lacking there. So what would I need to add to that so that I when I type xdate it a)adds a new line then b) inserts the date ? (win32) – Cups Jun 14 '11 at 14:32
  • @Cups: Just change it to `iab xdate =strftime("%d/%m/%y %H:%M:%S")` (I have added a `` before the `` to introduce a carriage return, which creates a new line) – abcd Jun 14 '11 at 14:43
3

See here

Press F5 in normal mode or in insert mode to insert the current datestamp:

:nnoremap <F5> "=strftime("%c")<CR>P
:inoremap <F5> <C-R>=strftime("%c")<CR>
Fredrik Pihl
  • 44,604
  • 7
  • 83
  • 130
-1

This should help you: Insert current date or time

Juho
  • 983
  • 5
  • 9