How can I use the output of an external command as an argument for tabnew?

In mine .bashrc

, I have the following short script to get the current date.

D(){ date +'%F'; }

      

In mine .vimrc

, I have the following two lines to do this so that I can use this function.

set shell=bash\ --login
set shellcmdflag=-ic

      

I have tested that the function works in vim

by checking that the following command will buffer the current date.

:r !D

      

However, I would like to use the output of this bash function as an argument for tabnew

so that I can open a file named current date in a new tab.

:tabnew !D

      

Unfortunately, the behavior of this command is to create a new tab with a literal filename !D

isntead of the output.

How can I get the output of an external command as an argument tabnew

instead?

+3


source to share


1 answer


The Backtick extension can be used to insert the output of external commands into Vim commands, usually as arguments:

:tabnew `date +'\%F'`

      

or



:tabnew `D`

      

Cm :help backtick-expansion

.

+4


source







All Articles