On 2020-06-23 14:02, Guido Milanese wrote:
>> :%s/<\([^>]*\)>/\=get({'TODAY':strftime('%c'), 'AUTHOR':$USER},
>> submatch(1), submatch(1))
>
> if you do not mind: why
>
> submatch(1), submatch(1)
>
> and not
>
> submatch(1), submatch(2)
The \(...\) captures a sub-group, and I only capture one of them, so
there's only submatch(0) (the whole thing including the "<" and ">")
and submatch(1) (the term inside them). If you want to keep the
brackets, the second one could be "submatch(0)" instead of
"submatch(1)".
It does a get() on that static dictionary/mapping, looking up the
term that was in those angle-brackets (the first submatch(1)). If it
finds the term, it returns the corresponding replacement. If it
doesn't find the term in the dictionary/mapping, it returns the
default (the same thing we're looking up, that second submatch(1), or
as mentioned above, you could keep the angle-brackets by returning the
whole original text with submatch(0)).
Hope that helps,
-tim