On 2021-09-04 18:43, Lifepillar wrote:
>> > :%s_^\[\(\d\+\)_\="[" . strftime("%c", submatch(1))_
> ⋮
> >> :%s/\[\zs\d\+\ze\]/\=strftime("%c", submatch(0))
>
> Learning Vim is a never-ending experience: I didn't know (or
> remember) about submatch()!
>
> Can you explain why \zs... \ze is to be preferred to capturing with
> \( and \)?
In this case, it was mostly to prevent the need to add the "[" back
in at the begining.
In this particular case, assuming every line had the timestamp at the
beginning, it could really have just skipped the "["/"]" aspects and
just replaced the first run of digits on each line without the need
to capture anything:
:%s/\d\+/\=strftime("%c", submatch(0))
but I find using the \zs and \ze makes it clear what I expect to
match/replace.
tl;dr: my weird personal preferences? ;-)
-tim