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



-- 
-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/20210904135305.028739dc%40bigbox.attlocal.net.

Reply via email to