Best way to insert timestamp in Vim?
Solution 1:
To make it work cross-platform, just put the following in your vimrc
:
nmap <F3> i<C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR><Esc>
imap <F3> <C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR>
Now you can just press F3 any time inside Vi/Vim and you'll get a timestamp like 2016-01-25 Mo 12:44
inserted at the cursor.
For a complete description of the available parameters check the documentation of the C function strftime().
Solution 2:
http://kenno.wordpress.com/2006/08/03/vim-tip-insert-time-stamp/
Tried it out, it works on my mac:
:r! date
produces:
Thu Sep 11 10:47:30 CEST 2008
This:
:r! date "+\%Y-\%m-\%d \%H:\%M:\%S"
produces:
2008-09-11 10:50:56
Solution 3:
Why is everybody using :r!
? Find a blank line and type !!date
from command-mode. Save a keystroke!
[n.b. This will pipe the current line into stdin, and then replace the line with the command output; hence the "find a blank line" part.]