EditPad Lite has a nice feature (CTRL-E, CTRL-I) which inserts a time stamp e.g. \"2008-09-11 10:34:53\" into your code.
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().
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.]
For a unix timestamp:
:r! date +\%s
You can also map this command to a key (for example F12) in VIM if you use it a lot:
Put this in your .vimrc:
map <F12> :r! date +\%s<cr>
Another quick way not included by previous answers: type-
!!date
!!date
!!date /t
As an extension to @Swaroop C H's answer,
^R=strftime("%FT%T%z")
is a more compact form that will also print the time zone (actually the difference from UTC, in an ISO-8601-compliant form).
If you prefer to use an external tool for some reason,
:r !date --rfc-3339=s
will give you a full RFC-3339 compliant timestamp; use ns
instead of s
for Spock-like precision, and pipe through tr ' ' T
to use a capital T instead of a space between date and time.
Also you might find it useful to know that
:source somefile.vim
will read in commands from somefile.vim
: this way you could set up a custom set of mappings, etc., and then load it when you're using vim on that account.