Wednesday, June 24, 2020

Re: Date in a boilerplate file

crystal clear!
thanks again,
guido

Il giorno mar 23 giu 2020 alle ore 23:51 Tim Chase <vim@tim.thechases.com> ha scritto:
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




--
Guido Milanese - Professor of Classics - Docteur H.C. Paris ICP
Universita' Cattolica d.S.C., Milano - Brescia
http://docenti.unicatt.it/ita/guido_fabrizio_milanese

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAFsD75THtGthR7GETDwvThVGrxhkQRtV6LuzwNXnx1yBQob6og%40mail.gmail.com.

No comments: