Tuesday, June 6, 2017

Re: Is there a simple way to |^a| and |^x| ?

On 2017-06-06 09:43, Erik Christiansen wrote:
> On 05.06.17 08:29, Tim Chase wrote:
> > While a side-stepping of your literal request, you can do
> > incrementing/decrementing in search replacements.
> >
> > For all numbers in a range:
> >
> > :'<,'>s/-\=\d\+/\=submatch(0)+22/g
> >
> > to add 22 to all numbers in that range of lines.
> ...
>
> Thanks Tim, I'll make a note of that for possible future use, but
> the crux remains: inc/dec of the magnitude, irrespective of sign.
> It looks like I'd need to cobble together a little bit of
> Vimscript, and map the functions to keys, maybe Alt-A and Alt-X.

Ah, I'd misunderstood that it was ignoring the sign and you wanted
to respect it. But you *wanted* to ignore the sign. Thus, you can
omit the optional sign:

:'<,'>s/\d\+/\=submatch(0)+22/g

or move the "\zs" after the optional minus-sign
to get the desired result:

:'<,'>s/property=-\=\zs\d\+/\=submatch(0)+22/g

In both cases, submatch(0) becomes just the number without the sign.

Beware the first one may do odd things in the event you have decimal
numbers in your file, so it would change "11.1" to "33.23" since you
don't anchor the left side.

-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.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment