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

map/range advice

Expand Messages
  • wave++
    Hi All. I was trying to run standard commands (like d/c/y) within a range of lines. :omap seemed the right way to do this, but I m blocked: omap r
    Message 1 of 6 , Jun 24, 2003
    • 0 Attachment
      Hi All. I was trying to run standard commands (like d/c/y) within a
      range of lines. :omap seemed the right way to do this, but I'm blocked:

      omap \r ?start?,/end/<CR>

      I supposed that omap could take a range of lines, but intead "d\r" cuts
      the text from the current line to /end/, without looking for ?start?.

      :?start?,/end/[command] instead do that as I wanted.

      I'd also like to use "\r" directly into :ex commands (to do :\r!tac for
      instance). Should I use [ci]map?

      Another question. Let's say that I want to filter the current paragraph
      with some external commands: do some easy way like this ":ap!command"
      exists (or could be done)? |text-objects| shouldn't produce "ranges"?
    • Benji Fisher
      ... With that :omap, d r should do the same thing as (starting in Normal mode) d?start?,/end/ . I guess you are trying to emulate something like
      Message 2 of 6 , Jun 24, 2003
      • 0 Attachment
        wave++ wrote:
        > Hi All. I was trying to run standard commands (like d/c/y) within a
        > range of lines. :omap seemed the right way to do this, but I'm blocked:
        >
        > omap \r ?start?,/end/<CR>
        >
        > I supposed that omap could take a range of lines, but intead "d\r" cuts
        > the text from the current line to /end/, without looking for ?start?.

        With that :omap, "d\r" should do the same thing as (starting in Normal
        mode) "d?start?,/end/<CR>" .

        I guess you are trying to emulate something like text-objects, where you
        can delete a range of characters that has the cursor in the middle. AFAIK,
        there is no way to do this with an :omap . The best solution I know is to use a
        :vmap like

        :vmap \r ?start<CR>o/end<CR>

        and then (starting from Normal mode) "v\rd".

        <plug>I did something similar in foo.vim, making :vmap's for i", a', etc., to
        select the "current" 'string'.
        http://www.vim.org/script.php?script_id=72
        </plug>

        > :?start?,/end/[command] instead do that as I wanted.
        >
        > I'd also like to use "\r" directly into :ex commands (to do :\r!tac for
        > instance). Should I use [ci]map?

        Yes. :cmap \r ...

        > Another question. Let's say that I want to filter the current paragraph
        > with some external commands: do some easy way like this ":ap!command"
        > exists (or could be done)? |text-objects| shouldn't produce "ranges"?

        If I understand correctly, you want the text-object (Operator-pending
        mode) meaning of ap, not the :ap command. Again, Visual mode is probably what
        you want. Starting from Normal mode, try "vap:" . This will select the
        paragraph in Visual mode, and leave you with

        :'<,'>

        at the command line. These two marks denote the start and end of the Visual
        selection. Note that Command-line mode is fundamentally line-oriented, so it
        does not matter whether you use v or V or <C-V>.

        HTH --Benji Fisher
      • Benji Fisher
        ... (It seems harder to type, though.) ... HTH --Benji Fisher
        Message 3 of 6 , Jun 24, 2003
        • 0 Attachment
          Benji Fisher wrote:
          > wave++ wrote:
          >
          >> Another question. Let's say that I want to filter the current paragraph
          >> with some external commands: do some easy way like this ":ap!command"
          >> exists (or could be done)? |text-objects| shouldn't produce "ranges"?
          >
          >
          > If I understand correctly, you want the text-object
          > (Operator-pending mode) meaning of ap, not the :ap command. Again,
          > Visual mode is probably what you want. Starting from Normal mode, try
          > "vap:" . This will select the paragraph in Visual mode, and leave you with
          >
          > :'<,'>
          >
          > at the command line. These two marks denote the start and end of the
          > Visual selection. Note that Command-line mode is fundamentally
          > line-oriented, so it does not matter whether you use v or V or <C-V>.

          I just realized, there is another way to do this:

          :'{,'}!command

          (It seems harder to type, though.)

          :help '{
          :help cmdline-ranges
          :help 10.3

          HTH --Benji Fisher
        • wave++
          ... Exactly. text-objects allow really fast selections. ... This requires an extra character to type :), but yes, this works as I wanted. Maybe there s some
          Message 4 of 6 , Jun 25, 2003
          • 0 Attachment
            On Tue, Jun 24, 2003 at 10:33:21PM -0400, Benji Fisher wrote:
            > I guess you are trying to emulate something like text-objects, where
            > you can delete a range of characters that has the cursor in the middle.

            Exactly. text-objects allow really fast selections.

            > AFAIK, there is no way to do this with an :omap . The best solution I know
            > is to use a :vmap like
            >
            > :vmap \r ?start<CR>o/end<CR>
            >
            > and then (starting from Normal mode) "v\rd".

            This requires an extra character to type :), but yes, this works as I
            wanted. Maybe there's some way to map this macro to an omap and make it
            work generically?

            :omap \R v\r[something]<CR>?

            > If I understand correctly, you want the text-object (Operator-pending
            > mode) meaning of ap, not the :ap command. Again, Visual mode is probably
            > what you want. Starting from Normal mode, try "vap:" . This will select
            > the paragraph in Visual mode, and leave you with
            >
            > :'<,'>
            >
            > at the command line. These two marks denote the start and end of the
            > Visual selection. Note that Command-line mode is fundamentally
            > line-oriented, so it does not matter whether you use v or V or <C-V>.

            Of course I used this method before, but I thought there was something
            faster to type. I suppose that several motion commands really searches
            for patterns (especially {}).
          • Piet Delport
            ... [snip] ... The simplest way is to type !ap followed by your command. It fills in the appropriate Ex range for you, similar to the way !2} or 5!! does. --
            Message 5 of 6 , Jul 2, 2003
            • 0 Attachment
              On Tue, 24 Jun 2003 at 22:39:29 -0400, Benji Fisher wrote:
              > Benji Fisher wrote:
              >> wave++ wrote:
              >>
              >>> Another question. Let's say that I want to filter the current
              >>> paragraph with some external commands: do some easy way like this
              >>> ":ap!command" exists (or could be done)? |text-objects| shouldn't
              >>> produce "ranges"?
              >>
              [snip]
              >
              > I just realized, there is another way to do this:
              >
              > :'{,'}!command

              The simplest way is to type !ap followed by your command. It fills in
              the appropriate Ex range for you, similar to the way !2} or 5!! does.

              --
              Piet Delport
              Today's subliminal thought is:
            • Benji Fisher
              ... I did not think of that one. I just tried it and noticed that it has the side effect of moving the cursor to the start of the paragraph. This may or may
              Message 6 of 6 , Jul 2, 2003
              • 0 Attachment
                Piet Delport wrote:
                > On Tue, 24 Jun 2003 at 22:39:29 -0400, Benji Fisher wrote:
                >
                >>Benji Fisher wrote:
                >>
                >>>wave++ wrote:
                >>>
                >>>
                >>>>Another question. Let's say that I want to filter the current
                >>>>paragraph with some external commands: do some easy way like this
                >>>>":ap!command" exists (or could be done)? |text-objects| shouldn't
                >>>>produce "ranges"?
                >>>
                > [snip]
                >
                >> I just realized, there is another way to do this:
                >>
                >>:'{,'}!command
                >
                >
                > The simplest way is to type !ap followed by your command. It fills in
                > the appropriate Ex range for you, similar to the way !2} or 5!! does.

                I did not think of that one. I just tried it and noticed that it has the
                side effect of moving the cursor to the start of the paragraph. This may or may
                not be A Good Thing, depending on what you want to do next.

                --Benji Fisher
              Your message has been successfully submitted and would be delivered to recipients shortly.