This post evolves each time I discover an exciting feature of Vim.

Pasting The Output of a Shell Command

Recently, I wondered if it was possible to display in a buffer a specific revision of a file taken from the Git repository of my project without leaving Vim. In my case, the file was removed in the latest branches on the project and I had to backport some logic that was in the original file.

I ended up on the read command and more precisely to the following form which is documented at :h read!:

:[range]r[ead] [++opt] !{cmd}

So if I want to fill an empty buffer with the file of a specified commit/branch:

:r !git show old_branch:src/build.sh

Insert The Current Date/Time

We can use the Vim internal strftime() function with the put command (see :h strftime() and :h put). Be careful, your system needs to have this function available.

So to insert the current date in the default format:

:pu=strftime('%c')