Loading ...
Sorry, an error occurred while loading the content.

Re: replace with a number sequence

Expand Messages
  • Naim Far
    Hi, ... 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
    Message 1 of 21 , Feb 1, 2007
    • 0 Attachment
      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.
      >
      >
    • Bill McCarthy
      ... -- Best regards, Bill
      Message 2 of 21 , Feb 1, 2007
      • 0 Attachment
        On Thu 1-Feb-07 8:23am -0600, Naim Far wrote:

        > 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

        --
        Best regards,
        Bill
      • Bill McCarthy
        ... When pattern is missing in :g or s:, it uses the last pattern of global, substitute or search - in the OPs example, it was being used after a search. For
        Message 3 of 21 , Feb 1, 2007
        • 0 Attachment
          On Thu 1-Feb-07 8:23am -0600, Naim Far wrote:

          > 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

          When pattern is missing in :g or s:, it uses the last
          pattern of global, substitute or search - in the OPs
          example, it was being used after a search.

          For \= see

          :h sub-replace-\=

          In the example, it is evaluating the variable - so its value
          is substituted.

          --
          Best regards,
          Bill
        • Naim Far
          Hi Vimers, Can anyone please help me with making the vim indent verilog files properly?! Thanx in advance!
          Message 4 of 21 , Feb 4, 2007
          • 0 Attachment
            Hi Vimers,

            Can anyone please help me with making the vim indent verilog files
            properly?!

            Thanx in advance!
          Your message has been successfully submitted and would be delivered to recipients shortly.