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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Erik Christiansen
Both ^a and ^x have proven very useful in a variety of scenarios. Now,
while editing some postscript, I sometimes have to decrement the
magnitude of a series of literal constants by a common amount, and if
there were mod variants of ^a and ^x, I'd be able to hit '.' on them
all, instead of having to ferret out the positive ones, then go back for
the negative, with all the scope for error which that entails.

Erik

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Tim Chase
On 2017-06-05 19:37, Erik Christiansen wrote:
> Both ^a and ^x have proven very useful in a variety of scenarios.
> Now, while editing some postscript, I sometimes have to decrement
> the magnitude of a series of literal constants by a common amount,
> and if there were mod variants of ^a and ^x, I'd be able to hit '.'
> on them all, instead of having to ferret out the positive ones,
> then go back for the negative, with all the scope for error which
> that entails.

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.  If you need more
context-aware targeting, you can use "\zs" and "\ze":

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

to only increment "property=###" by 22.

You can use any valid vim expression to the right of that
"\=" (though with a caveat regarding division, in which case I
recommend alternate delimiters:

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

so that the "/" isn't seen as a delimiter for the :s command).

-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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Erik Christiansen
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.

Erik

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Christian Brabandt

On Di, 06 Jun 2017, Erik Christiansen wrote:

> 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.

visually select the number without the sign should work.

Best,
Christian
--
Niemand ist so gut oder so schlecht, wie er während seiner Scheidung
gemacht wird.
                -- J.J. Disenberg

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Tim Chase
In reply to this post by Erik Christiansen
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Erik Christiansen
In reply to this post by Christian Brabandt
On 06.06.17 08:38, Christian Brabandt wrote:
>
> On Di, 06 Jun 2017, Erik Christiansen wrote:
>
> > 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.
>
> visually select the number without the sign should work.

Many thanks, Christian. I'll update my Vim, as it currently just says
"Bong" when I try that. (Was too busy using it to update today. :)

Erik

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Erik Christiansen
In reply to this post by Tim Chase
On 06.06.17 09:26, Tim Chase wrote:

> 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.

Fortunately the dimensions are all integer mm in this case, so that
would be OK. But the problem with Postscript (or generated CNC gcode for
that matter) is that the tendency to an excess of magic numbers risks
that some of them could be unrelated to the desired redimensioning. The
correct solution is to introduce more variables, then the whole problem
goes away. It just all takes time, and a quick dash for the finish line
was tempting.

Erik

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