There are two ways to do this.
The first one is interactive, using CTRL-R =
in the Ex command-line to enter an expression and evaluate it.
Start by typing the command as usual: :w myFile-
, then press CTRL-R
, =
. You'll now have a =
prompt where you can enter an expression. Enter strftime("%F")
and press "Enter", Vim will evaluate that to 2020-03-27 (assuming that's today's date) and will now display the command-line as :w myFile-2020-03-27
, which you can then execute or further edit as you like.
Another option is to use the :execute
command to execute a string as an Ex command. In which case you can simply use:
:exe 'w myFile-'.strftime("%F")
Note that .
is the string concatenation operator here. This latter form with :execute
is particularly useful in Vim scripts or functions.