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.
What is the best way to get this functionality in Vim?
(I am using Vim 6.1 on a Linux server via SSH. In the current situation a number of us share a login so I don't want to create abbreviations in the home directory if there is another built-in way to get a timestamp.)
Tabs and spaces in vim
Counting occurrences in Vim without marking the buffer changed
How to replace a character by a newline in Vim?
Tried it out, it works on my mac:.
Why is \r a newline for Vim?
Duplicate a whole line in Vim
Thu Sep 11 10:47:30 CEST 2008
What is the best way to force yourself to master vi? [closed]
:r! date "+\%Y-\%m-\%d \%H:\%M:\%S"
What is the difference between <C-C> and <C-[> in vim?
What is the most convincing command in Vim
Now you can just press F3 any time inside Vi/Vim and you'll get a timestamp like
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>
2016-01-25 Mo 12:44inserted at the cursor.. For a complete description of the available parameters check the documentation of the C function strftime()..
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,.
will give you a full RFC-3339 compliant timestamp; use
:r !date --rfc-3339=s
sfor Spock-like precision, and pipe through
tr ' ' Tto use a capital T instead of a space between date and time.. Also you might find it useful to know that.
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..
:r!? Find a blank line and type
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.].
(Edited the from above :) ) (Edit: change text part to code, so that .
:map <F3> :r! date +"\%Y-\%m-\%d \%H:\%M:\%S"<cr>
can be displayed).
:r! date +\%sYou 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>
Now in Insert mode it just type tds and as soon as I hit the space bar or return, I get the date and keep typing.. I put the
:iab <expr> tds strftime("%F %b %T")
%bin there, because I like seeing the month name.
%Fgives me something to sort by date.
I might change that to
%Y%m%dso there are no characters between the units..