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

Re: Repeat insert with a variable change...

Expand Messages
  • Thomas S. Urban
    On Sun, Jan 26, 2003 at 01:02:08 -0600, David Rock sent 1.9K bytes: * Thomas S. Urban [2003-01-25 13:03]: On Fri, Jan 24, 2003 at
    Message 1 of 10 , Jan 26, 2003
      On Sun, Jan 26, 2003 at 01:02:08 -0600, David Rock sent 1.9K bytes:
      > * Thomas S. Urban <scottu@...> [2003-01-25 13:03]:
      > > On Fri, Jan 24, 2003 at 22:30:30 -0500, Benji Fisher sent 0.7K bytes:
      > > > Thomas S. Urban wrote:
      > > > >On Fri, Jan 24, 2003 at 20:30:38 -0600, David Rock sent 1.1K bytes:
      > > > >
      > > > >>I would like to take the contents of a file, yank them and then put them
      > > > >>x number of times while changing a variable as I go.
      > > > >>
      > > > >>For example, take this section, with of a range of 1-5:
      > > > >>
      > > > >>[name-x]
      > > > >>item=foo
      > > > >>item2=bar
      > > > >>
      > > > >>Create this:
      > > > >>
      > > > >
      > > > ><snip>
      > > > >
      > > > >Recording is perfect for this kind of thing:
      > > > >
      > > > [snip]
      > > >
      > > > There is more than one way, of course. In Normal mode, try
      > >
      > > Very true.
      > >
      > > > ggyGG4p
      > > >
      > > > to yank the whole buffer and paste 4 copies, then
      > > >
      > > > :let cnt = 0
      > > > :g/\[name-x]/let cnt = cnt+1 | execute "s/x/" . cnt
      > > >
      > > > That is, for each "[name-x]" line, increment the counter and replace the
      > > > "x" with the current count.
      > > >
      > > Yours, trimmed and reeduced, as much as i could:
      > >
      > > ggyGG4p:let c=0 :g/-x]/let c=c+1|exe "s/x/".c
      > >
      > > == 46 chars
      > >
      > > Mine, trimmed and reduced:
      > >
      > > ggqq5yy4jp4wkq3@q
      > >
      > > == 18 chars
      > >
      > > I win! ;)
      >
      > Fine, it's shorter, but how does it handle incrementing so that:
      > [test-x] becomes
      > [test-1]
      > [test-2]
      > [test-3]
      > [test-4]
      > etc.
      >
      > In this circumstance, the other is a better general case, but yours is
      > still cute, too ;-)

      I forgot to mention that you had to change the first line to [test-1],
      sorry. Yeah, the other scheme is more general. Recording + use of C-X
      and C-A only get you addition and subtraction - you could get really
      crazy with expressions . Building incremented sets of blocks sure
      comes up often, though ....

      ;)




      --
      purpitation, n.:
      To take something off the grocery shelf, decide you
      don't want it, and then put it in another section.
      -- "Sniglets", Rich Hall & Friends
    • David Rock
      * Thomas S. Urban [2003-01-26 00:21]: I m still lost on one thing here. I was able to follow most of this pretty easily, but how does
      Message 2 of 10 , Jan 26, 2003
        * Thomas S. Urban <scottu@...> [2003-01-26 00:21]:

        I'm still lost on one thing here. I was able to follow most of this
        pretty easily, but how does the ^X work? How do I actually type this at
        the commandline?
        > > > ggqq5yy4jp4wkq3@q
        ^^ Is this Ctrl+V,Ctrl+X, or Shift+x, or what?
        >
        > I forgot to mention that you had to change the first line to [test-1],
        > sorry. Yeah, the other scheme is more general. Recording + use of C-X
        > and C-A only get you addition and subtraction - you could get really
        > crazy with expressions . Building incremented sets of blocks sure
        > comes up often, though ....

        Yeah, normally I would do something like this with python, but the
        question came up "can I do this in vim?" Obviously, I said yes, I just
        didn't know how. I knew _anything_ could be done in vim ;-)

        One of my Windows buddies has almost switched into a more productive
        world. He won't go to Linux (yet), but I think I have him hooked on vim
        ;-)

        --
        David Rock
        david@...
      • Thomas S. Urban
        ... All of this is in normal mode. The ^X means hit CTRL-X, which decrements the number the cursor is on (in normal mode). See ... and ... these are pretty
        Message 3 of 10 , Jan 26, 2003
          On Sun, Jan 26, 2003 at 11:13:48 -0600, David Rock sent 1.5K bytes:
          > * Thomas S. Urban <scottu@...> [2003-01-26 00:21]:
          >
          > I'm still lost on one thing here. I was able to follow most of this
          > pretty easily, but how does the ^X work? How do I actually type this at
          > the commandline?

          > > > > ggqq5yy4jp4wkq3@q
          > ^^ Is this Ctrl+V,Ctrl+X, or Shift+x, or what?

          All of this is in normal mode. The '^X' means hit CTRL-X, which
          decrements the number the cursor is on (in normal mode). See

          :help CTRL-X
          and
          :help CTRL-A

          these are pretty useful - you can use them with a count, or in
          combination with the dot operator to add the same number to another
          number again.

          > >
          > > I forgot to mention that you had to change the first line to [test-1],
          > > sorry. Yeah, the other scheme is more general. Recording + use of C-X
          > > and C-A only get you addition and subtraction - you could get really
          > > crazy with expressions . Building incremented sets of blocks sure
          > > comes up often, though ....
          >
          > Yeah, normally I would do something like this with python, but the
          > question came up "can I do this in vim?" Obviously, I said yes, I just
          > didn't know how. I knew _anything_ could be done in vim ;-)
          >
          > One of my Windows buddies has almost switched into a more productive
          > world. He won't go to Linux (yet), but I think I have him hooked on vim
          > ;-)

          Most of the windows developers at my work now have a copy of vim for
          "serious editing". Vim is the gateway drug;)


          --
          Failure to adjust for daylight savings time.
        • David Rock
          ... Cool, thanks. -- David Rock david@graniteweb.com
          Message 4 of 10 , Jan 26, 2003
            * Thomas S. Urban <scottu@...> [2003-01-26 09:35]:
            > On Sun, Jan 26, 2003 at 11:13:48 -0600, David Rock sent 1.5K bytes:
            > > * Thomas S. Urban <scottu@...> [2003-01-26 00:21]:
            > >
            > > I'm still lost on one thing here. I was able to follow most of this
            > > pretty easily, but how does the ^X work? How do I actually type this at
            > > the commandline?
            >
            > > > > > ggqq5yy4jp4wkq3@q
            > > ^^ Is this Ctrl+V,Ctrl+X, or Shift+x, or what?
            >
            > All of this is in normal mode. The '^X' means hit CTRL-X, which
            > decrements the number the cursor is on (in normal mode). See
            >
            > :help CTRL-X
            > and
            > :help CTRL-A
            >
            > these are pretty useful - you can use them with a count, or in
            > combination with the dot operator to add the same number to another
            > number again.

            Cool, thanks.

            --
            David Rock
            david@...
          Your message has been successfully submitted and would be delivered to recipients shortly.