Is your feature request about something that is currently impossible or hard to do? Please describe the problem.
It is not easy to include the value of a Vim script expression inside a heredoc:
vim9script
var lines =<< trim END
echo $HOME
END
echo lines
If we want $HOME to be evaluated, we need an extra call to a combination of map() and substitute():
vim9script
var lines =<< trim END
echo $HOME
END
lines->map((_, line) => line->substitute('$HOME', $HOME, ''))
echo lines
Which makes the code less readable, and is probably not always reliable in the general case (i.e. substitute() might replace tokens which we want to be left alone).
Describe the solution you'd like
Extend the backtick expansion syntax which supports Vim script expressions (the one documented at :help E1083) to heredocs:
With this feature, the previous snippet could be simplified into this:
vim9script
var lines =<< trim eval END
echo `=$HOME`
END
echo lines
Notice the presence of the new eval argument on the first line of the assigment:
var lines =<< trim eval END
^--^
It would be necessary to avoid breaking existing scripts. With eval, Vim would look for Vim script expressions to evaluate.
Describe alternatives you've considered
An alternative is to continue using an extra call to a combination of map() and substitute(), which – again – is less readable and less reliable than the proposed syntax.
Additional context
In bash, there are 2 kinds of heredocs. The ones which do not try to expand any parameter:
cat <<'EOF'
echo $HOME
EOF
And the ones which do:
The difference between the 2 depends on whether the end word is quoted. Currently, Vim script only supports the first kind. I think it would be useful to support the second one too.
Is your feature request about something that is currently impossible or hard to do? Please describe the problem.
It is not easy to include the value of a Vim script expression inside a heredoc:
If we want
$HOMEto be evaluated, we need an extra call to a combination ofmap()andsubstitute():Which makes the code less readable, and is probably not always reliable in the general case (i.e.
substitute()might replace tokens which we want to be left alone).Describe the solution you'd like
Extend the backtick expansion syntax which supports Vim script expressions (the one documented at
:help E1083) to heredocs:With this feature, the previous snippet could be simplified into this:
Notice the presence of the new
evalargument on the first line of the assigment:It would be necessary to avoid breaking existing scripts. With
eval, Vim would look for Vim script expressions to evaluate.Describe alternatives you've considered
An alternative is to continue using an extra call to a combination of
map()andsubstitute(), which – again – is less readable and less reliable than the proposed syntax.Additional context
In bash, there are 2 kinds of heredocs. The ones which do not try to expand any parameter:
And the ones which do:
The difference between the 2 depends on whether the end word is quoted. Currently, Vim script only supports the first kind. I think it would be useful to support the second one too.