0

I know about r! command to append text from bash output to vim under cursor. So for example issuing this command in vim:

:r! printf "abcd\n"

would append "abcd" into the vim buffer. But I am somehow unable to do similar with subshell involved. In file a.sh, I issue:

:r! printf "This file was created on %s" $(date +%m/%d/%y)

And the result is

This file was created on a.shs

some nonsense created from the filename. Why? (on normal terminal, there is no such problem, so I am assuming vim cannot handle subshells?)

milanHrabos
  • 2,010
  • 3
  • 11
  • 45

1 Answers1

-1

:r! printf "This file was created on \%s" "$(date +\%m/\%d/\%y)"

alef
  • 124
  • 4
  • 2
    This command does print the string "This file was created on \" followed by the name of the current edited file. pfrintf is not a command it's a function. Passing bash command retrurn values does not work as shown. – zzeroo Nov 13 '20 at 14:54
  • @zzeroo is also `/usr/bin/printf` – alef Nov 13 '20 at 17:27
  • @BDL `%` is the name of current file, as @zzeroo mentioned. The `\%` just escapes it. The `"$(date ...)"` means that the resulting stdout is given as a single parameter to `/usr/bin/printf` instead of more, like in "Fri" "Nov" "13" etc. – alef Nov 13 '20 at 19:06