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

replace with a number sequence

Expand Messages
  • jose isaias cabrera
    Greetings! I have these lines, UniqueID2 = lview.focusedItem.subItems.opIndex(0).text; Parent = lview.focusedItem.subItems.opIndex(0).text;
    Message 1 of 21 , Jan 28, 2007
      Greetings!

      I have these lines,

      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;
      txtCust.text = lview.focusedItem.subItems.opIndex(2).text;
      txtProj.text = lview.focusedItem.subItems.opIndex(3).text;
      txtbDate.text = lview.focusedItem.subItems.opIndex(4).text;
      txtdDate.text = lview.focusedItem.subItems.opIndex(5).text;
      txteDate.text = lview.focusedItem.subItems.opIndex(6).text;
      txtPM.text = lview.focusedItem.subItems.opIndex(7).text;
      txtLang.text = lview.focusedItem.subItems.opIndex(8).text;
      txtVendor.text = lview.focusedItem.subItems.opIndex(9).text;
      txtInvoice.text = lview.focusedItem.subItems.opIndex(10).text;
      txtPMFund.text = lview.focusedItem.subItems.opIndex(11).text;
      txtProjFund.text= lview.focusedItem.subItems.opIndex(12).text;
      txtA_No.text = lview.focusedItem.subItems.opIndex(13).text;
      txtNotes.text = lview.focusedItem.subItems.opIndex(14).text;
      txtStatus.text = lview.focusedItem.subItems.opIndex(15).text;

      and I would like to replace the number between the parens () to a sequential
      number starting from 0. ie,

      (0)
      (1)
      ...
      ...
      (19)

      etc.

      Any help would be greatly appreciated.

      josé
    • Tim Chase
      ... It should renumber them starting at zero for you. I d be glad to explain what that s doing if you have trouble un-opaquifying it :) -tim
      Message 2 of 21 , Jan 28, 2007
        > I have these lines,
        > 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;
        > txtCust.text = lview.focusedItem.subItems.opIndex(2).text;
        > txtProj.text = lview.focusedItem.subItems.opIndex(3).text;
        > txtbDate.text = lview.focusedItem.subItems.opIndex(4).text;
        > txtdDate.text = lview.focusedItem.subItems.opIndex(5).text;
        > txteDate.text = lview.focusedItem.subItems.opIndex(6).text;
        > txtPM.text = lview.focusedItem.subItems.opIndex(7).text;
        > txtLang.text = lview.focusedItem.subItems.opIndex(8).text;
        > txtVendor.text = lview.focusedItem.subItems.opIndex(9).text;
        > txtInvoice.text = lview.focusedItem.subItems.opIndex(10).text;
        > txtPMFund.text = lview.focusedItem.subItems.opIndex(11).text;
        > txtProjFund.text= lview.focusedItem.subItems.opIndex(12).text;
        > txtA_No.text = lview.focusedItem.subItems.opIndex(13).text;
        > txtNotes.text = lview.focusedItem.subItems.opIndex(14).text;
        > txtStatus.text = lview.focusedItem.subItems.opIndex(15).text;
        >
        > and I would like to replace the number between the parens () to a sequential
        > number starting from 0. ie,

        If you highlight the lines in question and issue the following:

        :'<,'>s/opIndex(\zs\d\+\ze)/\=line('.')-line("'<")

        It should renumber them starting at zero for you.

        I'd be glad to explain what that's doing if you have trouble
        un-opaquifying it :)

        -tim
      • Luke Vanderfluit
        Hi. ... I ve used the line function in the past. And it s something seems to recur frequently. Since I m always learning new things in vim, I d appreciate any
        Message 3 of 21 , Jan 28, 2007
          Hi.

          Tim Chase wrote:
          >> I have these lines,
          >> 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;
          >> txtCust.text = lview.focusedItem.subItems.opIndex(2).text;
          >> txtProj.text = lview.focusedItem.subItems.opIndex(3).text;
          >> txtbDate.text = lview.focusedItem.subItems.opIndex(4).text;
          >> txtdDate.text = lview.focusedItem.subItems.opIndex(5).text;
          >> txteDate.text = lview.focusedItem.subItems.opIndex(6).text;
          >> txtPM.text = lview.focusedItem.subItems.opIndex(7).text;
          >> txtLang.text = lview.focusedItem.subItems.opIndex(8).text;
          >> txtVendor.text = lview.focusedItem.subItems.opIndex(9).text;
          >> txtInvoice.text = lview.focusedItem.subItems.opIndex(10).text;
          >> txtPMFund.text = lview.focusedItem.subItems.opIndex(11).text;
          >> txtProjFund.text= lview.focusedItem.subItems.opIndex(12).text;
          >> txtA_No.text = lview.focusedItem.subItems.opIndex(13).text;
          >> txtNotes.text = lview.focusedItem.subItems.opIndex(14).text;
          >> txtStatus.text = lview.focusedItem.subItems.opIndex(15).text;
          >>
          >> and I would like to replace the number between the parens () to a sequential
          >> number starting from 0. ie,
          >>
          >
          > If you highlight the lines in question and issue the following:
          >
          > :'<,'>s/opIndex(\zs\d\+\ze)/\=line('.')-line("'<")
          >
          > It should renumber them starting at zero for you.
          >
          > I'd be glad to explain what that's doing if you have trouble
          > un-opaquifying it :)
          >
          >
          I've used the line function in the past. And it's something seems to
          recur frequently.
          Since I'm always learning new things in vim, I'd appreciate any
          instructive comment on your solution. The use of zs and ze is also
          interesting (-:

          Kind regards.
          Luke.


          > -tim
          >
          >
          >
          >
          >


          --
          Luke Vanderfluit
          Analyst / Web Programmer
          e3Learning.com.au
          08 8221 6422
        • Tim Chase
          ... It, and its mate getline() are commonly used in scripts, usually taking a line reference (such as . for the current line or x for a mark or $ for
          Message 4 of 21 , Jan 28, 2007
            >>> I have these lines,
            >>> UniqueID2 = lview.focusedItem.subItems.opIndex(0).text;
            >>> Parent = lview.focusedItem.subItems.opIndex(0).text;
            >>> Children = lview.focusedItem.subItems.opIndex(0).text;
            >>>
            >>> and I would like to replace the number between the parens () to a sequential
            >>> number starting from 0. ie,
            >>
            >> If you highlight the lines in question and issue the following:
            >>
            >> :'<,'>s/opIndex(\zs\d\+\ze)/\=line('.')-line("'<")
            >>
            >> It should renumber them starting at zero for you.
            >>
            >> I'd be glad to explain what that's doing if you have trouble
            >> un-opaquifying it :)
            >
            > I've used the line function in the past. And it's something seems to
            > recur frequently.

            It, and its mate "getline()" are commonly used in scripts,
            usually taking a line reference (such as "." for the current line
            or "'x" for a mark or "$" for the last line of the file)

            :help line(
            :help getline(

            > Since I'm always learning new things in vim, I'd appreciate any
            > instructive comment on your solution.
            > The use of zs and ze is also interesting (-:

            I'll try to address them both in the same pass. The \zs and \ze
            mark the beginning and end of the pattern in which I'm
            interested. This allows me to add context (the "opIndex(" and
            the closing paren) without worrying about extracting those pieces
            and putting them back in in the final expression. Thus, I'm only
            dealing with the numbers, but I know that those numbers are the
            ones in the opIndex() that I'm interested in.

            :help /\zs
            :help /\ze

            I now have as my "entire" pattern, the digits that I want to
            replace. I replace them with the results of evaluating an
            expression: \=

            :help sub-replace-special

            The math in question replaces the contents that were found (the
            digits) with the following result:

            line('.')-line("'<")

            The line('.') is the line number of the current match (or the
            beginning of the current match, if it had been multi-line). The
            second line("'<") is the line number of a mark. In this case,
            the "<" mark, which is the beginning of the range (as in, your
            "'<,'>" that shows up at the beginning of the line when you try
            to execute an Ex command within visual mode).

            Thus, the result of this on the first line (N) of the replacement
            will be N-N=0. The second line on which we replace this, it will
            have be (N+1)-N = 1 and so on until you get to the end of the
            range. If one wanted to count from 1, you could just use

            1+line(".")-line("'<")

            Or you could count by multiples of 2 (0,2,4,6,8...):

            2*(line(".")-line("'<"))

            or odd multiples of two (1,3,5,7,9...)

            1+2*(line(".")-line("'<"))

            and so on.

            Things get a little trickier if one wants to do the replacement
            in a single line of multiple instances...

            opInstance(1), opInstance(2), opInstance(3)

            One has to write a function that effects a global variable:

            let g:start=0
            function! Incrementer()
            let l:result = g:start
            let g:start = g:start + 1
            return l:result
            endfunction

            and then do something like

            :%s/regexp/\=Incrementer()/g

            It would be nice not to have to use global variables for
            something like that.

            Just a few further riffs on the original idea...Hope this helps
            understand and dissect the original so you can use/abuse it in
            the future. :)

            -tim
          • Suresh Govindachar
            Recently, Tim Chase wrote in the thread replace with a number sequence : ... Can t one initialize the unnamed register, @ and use a :g with a command along
            Message 5 of 21 , Jan 28, 2007
              Recently, Tim Chase wrote in the thread "replace
              with a number sequence":

              ...8<---

              > Things get a little trickier if one wants to do the replacement
              > in a single line of multiple instances...
              >
              > opInstance(1), opInstance(2), opInstance(3)
              >
              > One has to write a function that effects a global variable:
              >
              > let g:start=0
              > function! Incrementer()
              > let l:result = g:start
              > let g:start = g:start + 1
              > return l:result
              > endfunction
              >
              > and then do something like
              >
              > :%s/regexp/\=Incrementer()/g
              >
              > It would be nice not to have to use global variables for
              > something like that.

              Can't one initialize the unnamed register, @" and use a :g with
              a command along the lines of 'replace with @" and increment @"'

              (I tried some experiments to implement the above idea but could
              not do so. But my inability to implement it does not meant that
              it can't be done.)

              --Suresh
            • A.J.Mechelynck
              ... I don t see any advantage (and I see some inconvenients) in using a register rather than a variable; but you could do with a script variable (which could
              Message 6 of 21 , Jan 28, 2007
                Suresh Govindachar wrote:
                > Recently, Tim Chase wrote in the thread "replace
                > with a number sequence":
                >
                > ...8<---
                >
                > > Things get a little trickier if one wants to do the replacement
                > > in a single line of multiple instances...
                > >
                > > opInstance(1), opInstance(2), opInstance(3)
                > >
                > > One has to write a function that effects a global variable:
                > >
                > > let g:start=0
                > > function! Incrementer()
                > > let l:result = g:start
                > > let g:start = g:start + 1
                > > return l:result
                > > endfunction
                > >
                > > and then do something like
                > >
                > > :%s/regexp/\=Incrementer()/g
                > >
                > > It would be nice not to have to use global variables for
                > > something like that.
                >
                > Can't one initialize the unnamed register, @" and use a :g with
                > a command along the lines of 'replace with @" and increment @"'
                >
                > (I tried some experiments to implement the above idea but could
                > not do so. But my inability to implement it does not meant that
                > it can't be done.)
                >
                > --Suresh
                >
                >

                I don't see any advantage (and I see some inconvenients) in using a register
                rather than a variable; but you could do with a script variable (which could
                be used globally but only via the functions defined in the script):

                function SetStep(value)
                let s:stepvar = a:value
                endfunction

                function GetStep(increment)
                let s:stepvar += a:increment
                return s:stepvar
                endfunction

                call SetStep(-1)
                1,$s/OpInstance(\zs\n\+\ze)/\=GetStep(1)/g

                ...or a local variable to the buffer where you do the substitute (untested):

                function GetStep(varname, increment)
                exe "let" a:varname "+=" a:increment
                exe "return" a:varname
                endfunction

                let b:counter = -1
                1,$s/OpInstance(\zs\n\+\ze)/\=GetStep("b:counter", 1)/g


                Best regards,
                Tony.
              • ben lieb
                Alas, most of my clients give me text in Word Format. However even when I cut-paste from Notepad into gvim certain characters don t convert over, namely quotes
                Message 7 of 21 , Jan 28, 2007
                  Alas, most of my clients give me text in Word Format. However even when
                  I cut-paste from Notepad into gvim certain characters don't convert
                  over, namely quotes (single, double) and diacritics (áé...). Instead '
                  for example turns into ¿.

                  When I pasted in a lot of text, it can be very hard to convert all the
                  characters back. What can I do to avoid this in the first place (besides
                  dropping Winbloze, since that's not an option)?

                  converted in Carolina,
                  Ben
                • John Little
                  Hi IMHO simpler and more flexible (works if there are lines not matching ... A useful idiom I learned here. Usually I muck around with ordinary searches until
                  Message 8 of 21 , Jan 29, 2007
                    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
                  • A.J.Mechelynck
                    ... 1. On this mailing list, when you start a new topic, it is better to use Write New Message and not Reply . The latter f***s up threading for the people
                    Message 9 of 21 , Jan 29, 2007
                      ben lieb wrote:
                      > Alas, most of my clients give me text in Word Format. However even when
                      > I cut-paste from Notepad into gvim certain characters don't convert
                      > over, namely quotes (single, double) and diacritics (áé...). Instead '
                      > for example turns into ¿.
                      >
                      > When I pasted in a lot of text, it can be very hard to convert all the
                      > characters back. What can I do to avoid this in the first place (besides
                      > dropping Winbloze, since that's not an option)?
                      >
                      > converted in Carolina,
                      > Ben
                      >

                      1. On this mailing list, when you start a new topic, it is better to use
                      "Write New Message" and not "Reply". The latter f***s up threading for the
                      people who use it.

                      2. When pasting text which can contain "exotic" characters, make sure your
                      'encoding' can represent them. UTF-8 can, in principle, represent anything;
                      but in some cases you may still have to ask yourself: In which encoding was
                      the original text? The program which put the data into the clipboard did it
                      know what it was doing? Does the OS support a Unicode clipboard?

                      3. For data coming from a Windoze app, setting 'encoding' and/or
                      'fileencoding' to cp1252 can often be a good choice. (Similarly, if the data
                      came from a Mac you may want to try "macroman"; from Unix or from unknown
                      sources: Latin1 [aka ISO-8859-1] or ISO-8859-15 [aka Latin9].) These are for
                      "Western" text. For "Central European" Latin text, or for Greek, Cyrillic,
                      Hebrew, Arabic, Devanagari, Chinese/Japanese/Korean or other scripts there are
                      of course other values.

                      4. Remember: You cannot enter the data into Vim memory if your 'encoding'
                      doesn't have a slot for it; and even if it does, you cannot save the data do
                      disk if your 'fileencoding' isn't also able to represent it. Also, for most
                      encoding conversions (but not between Latin1 and UTF-8 and not from US-ASCII
                      to most other Latin encodings) you need iconv library support (i.e.,
                      has("iconv") must return a nonzero value).


                      Best regards,
                      Tony.
                    • jose isaias cabrera
                      Charles E Campbell Jr wrote, ... if this works, this is easier than the previous formula. I ll give it a try. gracias. josé
                      Message 10 of 21 , Jan 29, 2007
                        "Charles E Campbell Jr" wrote,

                        > jose isaias cabrera wrote:
                        >
                        >> <snip>
                        >> and I would like to replace the number between the parens () to a
                        >> sequential number starting from 0. ie,
                        >
                        > <snip>
                        >
                        > Hello!
                        >
                        > The visincr plugin addresses just this issue with ease:
                        >
                        > * place cursor on the 0 at the top
                        > * use ctrl-v (visual block) and move to highlight the column
                        > * press: :I
                        >
                        > Visincr can handle various forms of enumeration, too.
                        >
                        > You can get visincr from:
                        > http://mysite.verizon.net/astronaut/vim/index.html#VISINCR
                        > or from
                        > http://vim.sourceforge.net/scripts/script.php?script_id=670
                        >
                        > Quick overview:
                        >
                        > :I [#] left justified incremented list
                        > :II [# [zfill]] right justified incremented list
                        > :IO [#] left justified octal incremented list
                        > :IIO [# [zfill]] right justified octal incremented list
                        > :IX [#] left justified hex. incremented lsit
                        > :IIX [# [zfill]] right justified hex. incremented lsit
                        > :IYMD [# [zfill]] year/month/day incremented list
                        > :IMDY [# [zfill]] month/day/year incremented list
                        > :IDMY [# [zfill]] day/month/year incremented list
                        > :IA [#] alphameric incremented list
                        > :ID [#] dayname incremented list
                        > :IM [#] monthname incremented list

                        if this works, this is easier than the previous formula. I'll give it a
                        try.

                        gracias.

                        josé
                      • Mark Woodward
                        ... Just as additional info this method also lets you perform this sort of incremental substitution on letters. UniqueID2 =
                        Message 11 of 21 , Jan 31, 2007
                          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


                          cheers,


                          --
                          Mark
                        • jose isaias cabrera
                          Mark Woodward wrote, ... 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;
                          Message 12 of 21 , Jan 31, 2007
                            "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.
                          • Tom Whittock
                            ... which replaces the *first number* on every line in the visual selection. look at the difference between the two to see that the responses have all used
                            Message 13 of 21 , Jan 31, 2007
                              > 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.

                              Using a simple change to Tim Chase' original substitution response, you have:

                              :'<,'>s/\d\+/\=line('.')-line("'<")

                              which replaces the *first number* on every line in the visual
                              selection. look at the difference between the two to see that the
                              responses have all used opIndex as a marker to know what number is to
                              be operated on.

                              this modification doesn't really allow for any fine degree of control
                              (like selecting which number on a given line to increment), but it
                              works for the examples you've given.

                              if you don't want to type it in every time,
                              :vmap <C-I> :s/\d\+/\=line('.')-line("'<")<CR>
                              which adds ctrl-i as a key in visual mode to do the job.

                              the ex (colon) commands are one of the major parts of vim - I would
                              highly recommend learning them a bit more, if you want to get the most
                              out of the program. For me, without ex there would be very little
                              point in using vim at all - I couldn't even write to a file ;)

                              Cheers.
                            • jose isaias cabrera
                              Tom Whittock wrote, ... Ok, one last question on this. :-) Is there a way to start this from where the cursor is and end with the first non-matched instance?
                              Message 14 of 21 , Jan 31, 2007
                                "Tom Whittock" wrote,


                                >> 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.
                                >
                                > Using a simple change to Tim Chase' original substitution response, you
                                > have:
                                >
                                > :'<,'>s/\d\+/\=line('.')-line("'<")
                                >
                                > which replaces the *first number* on every line in the visual
                                > selection. look at the difference between the two to see that the
                                > responses have all used opIndex as a marker to know what number is to
                                > be operated on.
                                >
                                > this modification doesn't really allow for any fine degree of control
                                > (like selecting which number on a given line to increment), but it
                                > works for the examples you've given.
                                >
                                > if you don't want to type it in every time,
                                > :vmap <C-I> :s/\d\+/\=line('.')-line("'<")<CR>
                                > which adds ctrl-i as a key in visual mode to do the job.
                                >
                                > the ex (colon) commands are one of the major parts of vim - I would
                                > highly recommend learning them a bit more, if you want to get the most
                                > out of the program. For me, without ex there would be very little
                                > point in using vim at all - I couldn't even write to a file ;)

                                Ok, one last question on this. :-)

                                Is there a way to start this from where the cursor is and end with the first
                                non-matched instance? For example,

                                char[] str = null;

                                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;

                                int i = 0;

                                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;

                                So, if the cursor is on the first bla.* the first 6 lines will be numbered
                                sequentially and stop there. Is this possible?
                              • Tim Chase
                                ... [snip] ... Well, if you have the above mapping, you can then map ... which will visualize the block in question and then reduce the problem to the
                                Message 15 of 21 , Jan 31, 2007
                                  >> Using a simple change to Tim Chase' original substitution response, you
                                  >> have:
                                  [snip]
                                  >> if you don't want to type it in every time,
                                  >> :vmap <C-I> :s/\d\+/\=line('.')-line("'<")<CR>
                                  >> which adds ctrl-i as a key in visual mode to do the job.
                                  >
                                  > Ok, one last question on this. :-)
                                  >
                                  > Is there a way to start this from where the cursor is and end with the first
                                  > non-matched instance? For example,
                                  >
                                  > char[] str = null;
                                  >
                                  > 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;
                                  >
                                  > int i = 0;
                                  >
                                  > 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;
                                  >
                                  > So, if the cursor is on the first bla.* the first 6 lines will be numbered
                                  > sequentially and stop there. Is this possible?

                                  Well, if you have the above mapping, you can then map

                                  :nmap <f4> vip<c-i>

                                  which will visualize the block in question and then reduce the
                                  problem to the previously solved problem.

                                  If you plan to then expand this to auto-numbering blocks
                                  throughout your your document, you might try something like
                                  (broken into multiple lines for easy reading, but would be all
                                  one mappable line)

                                  :g/bla\.blah\.blahh\[\d/if
                                  getline(line('.')-1)=~'blah\.blah\.blahh\['
                                  | let counter = 0
                                  | endif
                                  | s/blahh\[\zs\d\+/\=counter/
                                  | let counter = counter + 1

                                  I haven't tested it (so there's likely some escaping I got
                                  wrong), but it should do similar to my previous mapping, only
                                  when the previous line doesn't match the target pattern, it
                                  resets the counter to zero. It might be reducable to something like

                                  :g/.../if getline(line('.')-1) =~ @/

                                  which might be a little easier to read/understand, as it uses the
                                  search register.

                                  Just a few ideas.

                                  -tim
                                • jose isaias cabrera
                                  Tim Chase wrote, ... Thanks. vim rocks! f4 What a beautiful world is this we live on! thanks, josé
                                  Message 16 of 21 , Jan 31, 2007
                                    "Tim Chase" wrote,

                                    >>> Using a simple change to Tim Chase' original substitution response, you
                                    >>> have:
                                    > [snip]
                                    >>> if you don't want to type it in every time,
                                    >>> :vmap <C-I> :s/\d\+/\=line('.')-line("'<")<CR>
                                    >>> which adds ctrl-i as a key in visual mode to do the job.
                                    >>
                                    >> Ok, one last question on this. :-)
                                    >>
                                    >> Is there a way to start this from where the cursor is and end with the
                                    >> first
                                    >> non-matched instance? For example,
                                    >>
                                    >> char[] str = null;
                                    >>
                                    >> 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;
                                    >>
                                    >> int i = 0;
                                    >>
                                    >> 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;
                                    >>
                                    >> So, if the cursor is on the first bla.* the first 6 lines will be
                                    >> numbered
                                    >> sequentially and stop there. Is this possible?
                                    >
                                    > Well, if you have the above mapping, you can then map
                                    >
                                    > :nmap <f4> vip<c-i>
                                    >
                                    > which will visualize the block in question and then reduce the problem to
                                    > the previously solved problem.
                                    >
                                    > If you plan to then expand this to auto-numbering blocks throughout your
                                    > your document, you might try something like (broken into multiple lines
                                    > for easy reading, but would be all one mappable line)
                                    >
                                    > :g/bla\.blah\.blahh\[\d/if getline(line('.')-1)=~'blah\.blah\.blahh\['
                                    > | let counter = 0
                                    > | endif
                                    > | s/blahh\[\zs\d\+/\=counter/
                                    > | let counter = counter + 1
                                    >
                                    > I haven't tested it (so there's likely some escaping I got wrong), but it
                                    > should do similar to my previous mapping, only when the previous line
                                    > doesn't match the target pattern, it resets the counter to zero. It might
                                    > be reducable to something like
                                    >
                                    > :g/.../if getline(line('.')-1) =~ @/
                                    >
                                    > which might be a little easier to read/understand, as it uses the search
                                    > register.
                                    >
                                    > Just a few ideas.

                                    Thanks. vim rocks!

                                    f4<CR>

                                    What a beautiful world is this we live on!

                                    thanks,

                                    josé
                                  • Matthew Winn
                                    On Wed, 31 Jan 2007 15:23:36 +0000, Tom Whittock ... Unless you use ZZ. -- Matthew Winn
                                    Message 17 of 21 , Feb 1, 2007
                                      On Wed, 31 Jan 2007 15:23:36 +0000, "Tom Whittock"
                                      <tom.whittock@...> wrote:

                                      > the ex (colon) commands are one of the major parts of vim - I would
                                      > highly recommend learning them a bit more, if you want to get the most
                                      > out of the program. For me, without ex there would be very little
                                      > point in using vim at all - I couldn't even write to a file ;)

                                      Unless you use ZZ.

                                      --
                                      Matthew Winn
                                    • 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 18 of 21 , Feb 1, 2007
                                        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 19 of 21 , Feb 1, 2007
                                          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 20 of 21 , Feb 1, 2007
                                            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 21 of 21 , Feb 4, 2007
                                              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.