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

RE: Supplying repeat count for part of a macro

Expand Messages
  • Dave Eggum
    Bob, Block-wise editing eliminates the need for this macro: see :help blockwise-operators Select a visual block, type: I{string} and the string you
    Message 1 of 6 , Aug 2, 2004
    • 0 Attachment
      Bob,

      Block-wise editing eliminates the need for this macro:

      see :help blockwise-operators

      Select a visual block, type:

      I{string}<ESC>

      and the string you specified is inserted at the begging of each visual
      block, also, your cursor ends up where you started.

      A{string}<ESC> is really useful too...

      Dave

      -----Original Message-----
      From: Trebor Sreyb [mailto:tsreyb@...]
      Sent: Monday, August 02, 2004 1:16 PM
      To: vim@...
      Subject: Supplying repeat count for part of a macro


      I use the following definitions:

      :let e = "kmmj.`m"
      :map <F12> @e

      These allow me to apply the same change in the same
      column over a series of lines (from last line on up).
      By simply hitting F12 the desired number of times my
      changes are applied very easily.

      Because some of my files have lots of column-aligned
      text, these macros have become extremely useful.

      Also, by specifying a repeat count before pressing
      F12, I can easily make the same edit to many lines
      with very few keystrokes.

      However, the final enhancement I'd like to make is to
      mark the initial cursor location (prior to the first
      edit), apply F12 some specified number of times, and
      finally return to the original location.

      In other words, I'd like to do this as follows
      (example using 15 lines to be edited):

      15<F12>

      When completed, the cursor is at the same spot it was
      when I first typed the '15'.

      But I cannot come up with a solution. I thought of
      defining another macro that calls @e, but it would
      need to know how many times to call @e.

      Is there a register that saves the most recent Repeat
      Count? I can't find such a register.

      Any suggestions welcome.

      thanks,
      -Bob
      Andover, MA



      __________________________________
      Do you Yahoo!?
      Yahoo! Mail - 50x more storage than other providers!
      http://promotions.yahoo.com/new_mail
    • Moshe Kaminsky
      Hi, ... There are variables, v:count and v:count1 Moshe
      Message 2 of 6 , Aug 2, 2004
      • 0 Attachment
        Hi,

        * Trebor Sreyb <tsreyb@...> [02/08/04 23:18]:
        > Is there a register that saves the most recent Repeat
        > Count? I can't find such a register.

        There are variables, v:count and v:count1

        Moshe
        >
        > Any suggestions welcome.
        >
        > thanks,
        > -Bob
        > Andover, MA
        >
        >
        >
        > __________________________________
        > Do you Yahoo!?
        > Yahoo! Mail - 50x more storage than other providers!
        > http://promotions.yahoo.com/new_mail
        >
      • Benji Fisher
        ... It might be simpler to map to call a function, rather than ... let l = line( . ) let c = col( . ) let cnt = v:count1 while cnt let cnt = cnt - 1
        Message 3 of 6 , Aug 2, 2004
        • 0 Attachment
          On Mon, Aug 02, 2004 at 01:15:32PM -0700, Trebor Sreyb wrote:
          > I use the following definitions:
          >
          > :let e = "kmmj.`m"
          > :map <F12> @e
          >
          > These allow me to apply the same change in the same
          > column over a series of lines (from last line on up).
          > By simply hitting F12 the desired number of times my
          > changes are applied very easily.
          >
          > Because some of my files have lots of column-aligned
          > text, these macros have become extremely useful.
          >
          > Also, by specifying a repeat count before pressing
          > F12, I can easily make the same edit to many lines
          > with very few keystrokes.
          >
          > However, the final enhancement I'd like to make is to
          > mark the initial cursor location (prior to the first
          > edit), apply F12 some specified number of times, and
          > finally return to the original location.
          >
          > In other words, I'd like to do this as follows
          > (example using 15 lines to be edited):
          >
          > 15<F12>
          >
          > When completed, the cursor is at the same spot it was
          > when I first typed the '15'.
          >
          > But I cannot come up with a solution. I thought of
          > defining another macro that calls @e, but it would
          > need to know how many times to call @e.
          >
          > Is there a register that saves the most recent Repeat
          > Count? I can't find such a register.
          >
          > Any suggestions welcome.

          It might be simpler to map <F12> to call a function, rather than
          executing a macro. Something along these lines (untested):

          :nmap <F12> :<C-U>call ColumnRepeat()<CR>

          :fun! ColumnRepeat()
          let l = line(".")
          let c = col(".")
          let cnt = v:count1
          while cnt
          let cnt = cnt - 1
          normal kmmj.`m
          endwhile
          call cursor(l,c)
          endfun

          If you use <F12> without a count, then <C-U> does nothing and cnt is
          initialized to 1. If you call it with a count, then <C-U> cancels the
          count and cnt is initialized to the count.

          IIRC, there was a bug with using "normal ." in a function, but it
          was fixed before vim 6.3 was released.

          HTH --Benji Fisher
        • Trebor Sreyb
          Thanks, Dave, block-wise seems more appropriate for my goal. Only problem I ve had is that my version of vim (6.2) does not leave my cursor where I started,
          Message 4 of 6 , Aug 2, 2004
          • 0 Attachment
            Thanks, Dave, block-wise seems more appropriate for my
            goal.

            Only problem I've had is that my version of vim (6.2)
            does not leave my cursor where I started, using
            I{string}<ESC>. Are you sure it is supposed to return
            to the starting point?

            I noticed, however, that after the insert, `]
            (backtick-]) gets me there.

            Same with other operations (eg, x<ESC>) - I'm left at
            the ending point, not the starting point.

            I'd really like to be returned to my starting point,
            so any further suggestions appreciated.

            Others came up with solutions based more closely to my
            original approach. However, blockwise operations seems
            the most straightforward approach.

            thanks,
            -bb






            --- Dave Eggum <deggum@...> wrote:

            > Bob,
            >
            > Block-wise editing eliminates the need for this
            > macro:
            >
            > see :help blockwise-operators
            >
            > Select a visual block, type:
            >
            > I{string}<ESC>
            >
            > and the string you specified is inserted at the
            > begging of each visual
            > block, also, your cursor ends up where you started.
            >
            > A{string}<ESC> is really useful too...
            >
            > Dave
            >
            > -----Original Message-----
            > From: Trebor Sreyb [mailto:tsreyb@...]
            > Sent: Monday, August 02, 2004 1:16 PM
            > To: vim@...
            > Subject: Supplying repeat count for part of a macro
            >
            >
            > I use the following definitions:
            >
            > :let e = "kmmj.`m"
            > :map <F12> @e
            >
            > These allow me to apply the same change in the same
            > column over a series of lines (from last line on
            > up).
            > By simply hitting F12 the desired number of times my
            > changes are applied very easily.
            >
            > Because some of my files have lots of column-aligned
            > text, these macros have become extremely useful.
            >
            > Also, by specifying a repeat count before pressing
            > F12, I can easily make the same edit to many lines
            > with very few keystrokes.
            >
            > However, the final enhancement I'd like to make is
            > to
            > mark the initial cursor location (prior to the first
            > edit), apply F12 some specified number of times, and
            > finally return to the original location.
            >
            > In other words, I'd like to do this as follows
            > (example using 15 lines to be edited):
            >
            > 15<F12>
            >
            > When completed, the cursor is at the same spot it
            > was
            > when I first typed the '15'.
            >
            > But I cannot come up with a solution. I thought of
            > defining another macro that calls @e, but it would
            > need to know how many times to call @e.
            >
            > Is there a register that saves the most recent
            > Repeat
            > Count? I can't find such a register.
            >
            > Any suggestions welcome.
            >
            > thanks,
            > -Bob
            > Andover, MA
            >
            >
            >
            > __________________________________
            > Do you Yahoo!?
            > Yahoo! Mail - 50x more storage than other providers!
            > http://promotions.yahoo.com/new_mail
            >
            >




            __________________________________
            Do you Yahoo!?
            New and Improved Yahoo! Mail - Send 10MB messages!
            http://promotions.yahoo.com/new_mail
          • Dave Eggum
            Hi Bob, Hmmm.... After a little more experimenting, I see that the cursor always returns to the top left corner of the selected block, regardless of where the
            Message 5 of 6 , Aug 3, 2004
            • 0 Attachment
              Hi Bob,

              Hmmm.... After a little more experimenting, I see that the cursor always
              returns to the top left corner of the selected block, regardless of where
              the true originating point was. So, my suggested solution returns your
              cursor to the beginning location only if you start at the top-left. :)
              (However, that works for me because I usually block-wise select to the right
              and down, and the ending location of the cursor isn't all that crucial to
              me.) Also, it seems that '] only works correctly if you start at the bottom
              right corner, which it sounds like you are accustomed to doing.

              Sounds like Benji's idea of creating a function that would remember, then
              restore, your cursor position would work best for you. I can't think of a
              way to get both the block-wise operations and cursor-return features rolled
              into one. You may be stuck with one or the other.

              Good luck,
              Dave

              -----Original Message-----
              From: Trebor Sreyb [mailto:tsreyb@...]
              Sent: Monday, August 02, 2004 8:49 PM
              To: vim@...
              Subject: RE: Supplying repeat count for part of a macro


              Thanks, Dave, block-wise seems more appropriate for my
              goal.

              Only problem I've had is that my version of vim (6.2)
              does not leave my cursor where I started, using
              I{string}<ESC>. Are you sure it is supposed to return
              to the starting point?

              I noticed, however, that after the insert, `]
              (backtick-]) gets me there.

              Same with other operations (eg, x<ESC>) - I'm left at
              the ending point, not the starting point.

              I'd really like to be returned to my starting point,
              so any further suggestions appreciated.

              Others came up with solutions based more closely to my
              original approach. However, blockwise operations seems
              the most straightforward approach.

              thanks,
              -bb






              --- Dave Eggum <deggum@...> wrote:

              > Bob,
              >
              > Block-wise editing eliminates the need for this
              > macro:
              >
              > see :help blockwise-operators
              >
              > Select a visual block, type:
              >
              > I{string}<ESC>
              >
              > and the string you specified is inserted at the
              > begging of each visual
              > block, also, your cursor ends up where you started.
              >
              > A{string}<ESC> is really useful too...
              >
              > Dave
              >
              > -----Original Message-----
              > From: Trebor Sreyb [mailto:tsreyb@...]
              > Sent: Monday, August 02, 2004 1:16 PM
              > To: vim@...
              > Subject: Supplying repeat count for part of a macro
              >
              >
              > I use the following definitions:
              >
              > :let e = "kmmj.`m"
              > :map <F12> @e
              >
              > These allow me to apply the same change in the same
              > column over a series of lines (from last line on
              > up).
              > By simply hitting F12 the desired number of times my
              > changes are applied very easily.
              >
              > Because some of my files have lots of column-aligned
              > text, these macros have become extremely useful.
              >
              > Also, by specifying a repeat count before pressing
              > F12, I can easily make the same edit to many lines
              > with very few keystrokes.
              >
              > However, the final enhancement I'd like to make is
              > to
              > mark the initial cursor location (prior to the first
              > edit), apply F12 some specified number of times, and
              > finally return to the original location.
              >
              > In other words, I'd like to do this as follows
              > (example using 15 lines to be edited):
              >
              > 15<F12>
              >
              > When completed, the cursor is at the same spot it
              > was
              > when I first typed the '15'.
              >
              > But I cannot come up with a solution. I thought of
              > defining another macro that calls @e, but it would
              > need to know how many times to call @e.
              >
              > Is there a register that saves the most recent
              > Repeat
              > Count? I can't find such a register.
              >
              > Any suggestions welcome.
              >
              > thanks,
              > -Bob
              > Andover, MA
              >
              >
              >
              > __________________________________
              > Do you Yahoo!?
              > Yahoo! Mail - 50x more storage than other providers!
              > http://promotions.yahoo.com/new_mail
              >
              >




              __________________________________
              Do you Yahoo!?
              New and Improved Yahoo! Mail - Send 10MB messages!
              http://promotions.yahoo.com/new_mail
            Your message has been successfully submitted and would be delivered to recipients shortly.