Tuesday, June 23, 2020

Re: Date in a boilerplate file

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


--
--
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/20200623165139.21134202%40bigbox.attlocal.net.

No comments:

Post a Comment