Hi,

I liked the following replacement command, and I found it very usefull:
 :let n=0|g//s//\=n/|let n+=1

But, could anyone please explain the way it works?!
I used the "help :=" to try and understand it, but the vim help says the ":=" command displays the line number, which cannot explain the way the command above works

Thanx in advance...



jose isaias cabrera wrote:


"Mark Woodward" wrote,

On Mon, 2007-01-29 at 21:57 +1300, John Little wrote:

Hi

IMHO simpler and more flexible (works if there are lines not matching
the pattern) is:

    :let n=0 | g/opIndex(\zs\d\+/s//\=n/|let n+=1

A useful idiom I learned here.  Usually I muck around with ordinary
searches until the search highlighting shows I've got it right, then

    :let n=0|g//s//\=n/|let n+=1

is what I have to remember, and it's obvious what the start and increment are.

John


Just as additional info this method also lets you perform this sort of
incremental substitution on letters.

     UniqueID2       = lview.focusedItem.subItems.opIndex(0).text;
     Parent          = lview.focusedItem.subItems.opIndex(0).text;
     Children        = lview.focusedItem.subItems.opIndex(0).text;
     login           = lview.focusedItem.subItems.opIndex(1).text;

let i=97|g/opIndex(\zs\d\+/s//\=nr2char(i)/|let i=i+1

     UniqueID2       = lview.focusedItem.subItems.opIndex(a).text;
     Parent          = lview.focusedItem.subItems.opIndex(b).text;
     Children        = lview.focusedItem.subItems.opIndex(c).text;
     login           = lview.focusedItem.subItems.opIndex(d).text;

let i=65|g/opIndex(\zs\d\+/s//\=nr2char(i)/|let i=i+1

     UniqueID2       = lview.focusedItem.subItems.opIndex(A).text;
     Parent          = lview.focusedItem.subItems.opIndex(B).text;
     Children        = lview.focusedItem.subItems.opIndex(C).text;
     login           = lview.focusedItem.subItems.opIndex(D).text;


:h nr2char



Since you brought it up, I also have this other situation,

bla.blah.blahh[0].text;
bla.blah.blahh[0].text;
bla.blah.blahh[0].text;
bla.blah.blahh[0].text;
bla.blah.blahh[0].text;
bla.blah.blahh[0].text;

I tried using the original solution you gave me,

:let n=0 | g/opIndex(\zs\d\+/s//\=n/|let n+=1

but it kept going to the same spot as before. I will not change the [#]. Where is the match for (? I can't figure it out. The next version of vim should have an easier way of doing this. I constantly have to copy from vim and paste to TextPad and doing it there and then copy from TextPad back to vim. Yes, I know I could make a function and assign a key to it, but these kind of things should be just built in. I know, I am a picky guy, aren't I? :-)

thanks.




Reply via email to