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')

Update Plugin Help Tags

Sometimes it can occur that some plugin’s help is not available. If the plugins you use are installed via the Vim 8’s plugins manager, you can simply use the following command to regenerate all the help tags of all the installed plugins

:helptags ALL

More info there: :h helptags

Clearing the Search Pattern

When search highlighting is enabled, you might want to clear the highlighted patterns. One solution could be to disable the highlighting with the command :noh. This can be cumbersome because you will need to enable it again on your next search.

A better way is probably to clear the last search pattern register as shown below:

:let @/=""

More info there: :h noh and :h registers