VI / VIM: Insert Current Date / Time

VI / VIM: Insert Current Date / Time

To insert the current date and time in Vim, you can use the strftime() function, which is available in Vim's expression evaluation feature.

To insert the current date, you can use the following command:

re‮l:ot ref‬autturi.com
:put =strftime('%c')

This will insert the current date and time in the format Sun Sep 16 01:03:52 1973. You can customize the format of the date and time by specifying a different format string. For example, to insert the date in the format YYYY-MM-DD, you can use:

:put =strftime('%Y-%m-%d')

To insert the current time, you can use a similar command:

:put =strftime('%H:%M:%S')

This will insert the current time in the format HH:MM:SS. Again, you can customize the format of the time by specifying a different format string.

You can find more information about the strftime() function and the available format strings in the Vim documentation by typing :help strftime within Vim.

Created Time:2017-10-30 14:27:31  Author:lautturi