Vim formatted print date to current file

Viewed 34

I am trying to print the current formatted as Mon, 1 Jan 2022 into my current file in vim. So far I've tried the following command, but the % sign gets put into the command as the current file.

:0r !date '+%a, %d %b %Y'

This ends up giving me an output similar to seen below.

/home/user/file.txta, /home/user/file.txtd /home/user/fileb /home/user/fileY

The issue is that the path to the current file is put in place for % as vim does, but that is causing issues for the current use case.

Any help is appreciated

1 Answers

The immediate solution is obviously to escape the %:

:0r !date '+\%a, \%d \%b \%Y'

But you might be interested by the built-in :help strftime(), which doesn't require escaping:

:0put=strftime('%a, %d %b %Y')
Related