≡ Menu

VI / VIM: Insert Current Date / Time

How do I display and insert current date and/or time under vi or VIM text editor?

You can use external command as follows to insert the current date and time:
:r !date
OR just type !!date (press ESC key followed by !! and than type date)
!!date
Sample outputs:

Fig.01: Insert date and time into Vim

Fig.01: Insert date and time into Vim

Sysadmin because even developers need heroes!!!

Share this tutorial on:
{ 2 comments… add one }
  • Bill November 22, 2010, 6:43 pm

    Put the date in a variable:

    TODAY=`date +”%A %B %e at %I:%M”
    echo $TODAY

    Put this in a script and the variable TODAY is updated every time the script executes. The data string is formatted us the plus sign with each element preceded by the percent. Quote the whole string to preserve and spaces.

    Bill

  • joreveur April 20, 2016, 9:06 am

    with windows

    :r! date/T

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , , , ,