decrease number?

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

decrease number?

stosss
I have several hundred lines like the one below:

<line x1="20"  y1="45"  x2="820" y2="45"  stroke-width="1" stroke="#c0c0c0" />

I want to change them like this:

<line x1="10"  y1="35"  x2="810" y2="35"  stroke-width="1" stroke="#c0c0c0" />

The "ten" place holder needs to decrease by one.
x1="20" y1="45" x2="820" y2="45"

Can someone point me to something that would show me a fast way to do this?

I am thinking some how I should be able to use CTRL-X in a search and replace but I don't know how to do it. I am guessing '\=' would be used. I really don't know how to put this together.

Thanks

--
--
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: decrease number?

stosss
Placing cursor on the number and typing 10CTRL-X reduces it by the desired amount but how do I do it in a search and replace pattern?

On Mon, Jun 19, 2017 at 7:14 PM, stosss <[hidden email]> wrote:
I have several hundred lines like the one below:

<line x1="20"  y1="45"  x2="820" y2="45"  stroke-width="1" stroke="#c0c0c0" />

I want to change them like this:

<line x1="10"  y1="35"  x2="810" y2="35"  stroke-width="1" stroke="#c0c0c0" />

The "ten" place holder needs to decrease by one.
x1="20" y1="45" x2="820" y2="45"

Can someone point me to something that would show me a fast way to do this?

I am thinking some how I should be able to use CTRL-X in a search and replace but I don't know how to do it. I am guessing '\=' would be used. I really don't know how to put this together.

Thanks

--
--
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: decrease number?

John Passaro
use the expression register:

s/\v\w+\="\zs\d\d+\ze"/\=submatch(0)-10/g



On Mon, Jun 19, 2017 at 9:59 PM, stosss <[hidden email]> wrote:
Placing cursor on the number and typing 10CTRL-X reduces it by the desired amount but how do I do it in a search and replace pattern?

On Mon, Jun 19, 2017 at 7:14 PM, stosss <[hidden email]> wrote:
I have several hundred lines like the one below:

<line x1="20"  y1="45"  x2="820" y2="45"  stroke-width="1" stroke="#c0c0c0" />

I want to change them like this:

<line x1="10"  y1="35"  x2="810" y2="35"  stroke-width="1" stroke="#c0c0c0" />

The "ten" place holder needs to decrease by one.
x1="20" y1="45" x2="820" y2="45"

Can someone point me to something that would show me a fast way to do this?

I am thinking some how I should be able to use CTRL-X in a search and replace but I don't know how to do it. I am guessing '\=' would be used. I really don't know how to put this together.

Thanks

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

--
--
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: decrease number?

stosss
Thank You John! Awesome!

On Mon, Jun 19, 2017 at 8:29 PM, John Passaro <[hidden email]> wrote:
use the expression register:

s/\v\w+\="\zs\d\d+\ze"/\=submatch(0)-10/g


John Passaro
<a href="tel:(917)%20678-8293" value="+19176788293" target="_blank">(917) 678-8293

On Mon, Jun 19, 2017 at 9:59 PM, stosss <[hidden email]> wrote:
Placing cursor on the number and typing 10CTRL-X reduces it by the desired amount but how do I do it in a search and replace pattern?

On Mon, Jun 19, 2017 at 7:14 PM, stosss <[hidden email]> wrote:
I have several hundred lines like the one below:

<line x1="20"  y1="45"  x2="820" y2="45"  stroke-width="1" stroke="#c0c0c0" />

I want to change them like this:

<line x1="10"  y1="35"  x2="810" y2="35"  stroke-width="1" stroke="#c0c0c0" />

The "ten" place holder needs to decrease by one.
x1="20" y1="45" x2="820" y2="45"

Can someone point me to something that would show me a fast way to do this?

I am thinking some how I should be able to use CTRL-X in a search and replace but I don't know how to do it. I am guessing '\=' would be used. I really don't know how to put this together.

Thanks

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

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

--
--
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: decrease number?

Tim Chase
In reply to this post by stosss
On 2017-06-19 19:14, stosss wrote:

> <line x1="20"  y1="45"  x2="820" y2="45"  stroke-width="1"
> stroke="#c0c0c0" />  
>
> I want to change them like this:
>
> <line x1="10"  y1="35"  x2="810" y2="35"  stroke-width="1"
> stroke="#c0c0c0" />  
>
> The "ten" place holder needs to decrease by one.
> x1="20" y1="45" x2="820" y2="45"
>
> Can someone point me to something that would show me a fast way to
> do this?
>
> I am thinking some how I should be able to use CTRL-X in a search
> and replace but I don't know how to do it. I am guessing '\=' would
> be used. I really don't know how to put this together.

I'd go with your "\=" suggestion.  Something like

 :%s/\<[xy][12]="\zs[^"]*\ze"/\=submatch(0)-10/g

This only finds x1, x2, y1, and y2.  You can relax the pattern a bit
if there are other variable-names in question.

-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: decrease number?

Tim Chase
In reply to this post by John Passaro
On 2017-06-19 22:29, John Passaro wrote:
> use the expression register:
>
> s/\v\w+\="\zs\d\d+\ze"/\=submatch(0)-10/g

Beware that this catches any variable name (not just [xy][12] which
may or may not be what you want), and also doesn't catch
negative-number values.

But for the general case of the example you (OP) gave, John's works
well too.

-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: decrease number?

stosss
Thanks Tim,

Johns did work exactly the way I wanted it to.

I like yours too.

On Mon, Jun 19, 2017 at 8:37 PM, Tim Chase <[hidden email]> wrote:
On 2017-06-19 22:29, John Passaro wrote:
> use the expression register:
>
> s/\v\w+\="\zs\d\d+\ze"/\=submatch(0)-10/g

Beware that this catches any variable name (not just [xy][12] which
may or may not be what you want), and also doesn't catch
negative-number values.

But for the general case of the example you (OP) gave, John's works
well too.

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

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