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

Re: Jump within function

Expand Messages
  • kbosau@web.de
    ... Hi Piet! Works perfectly! Thanks a lot! Klaus
    Message 1 of 10 , Oct 31 1:53 PM
      On 31 Oct 2002 at 13:44, Piet Delport wrote:

      > On Thu, 31 Oct 2002 at 09:42:11 +0100, kbosau@... wrote:
      >
      > [...]
      >
      > To use the <> notation in strings like you did above, you have to escape
      > the first < with a backslash, otherwise the sequence gets interpreted
      > literally[1]. See :h :exec and :h expr-quote for more on this.
      >
      > Like Antoine said, the other problem is that your function doesn't
      > search from the beginning of the file. Using `gg' before the search
      > helps, but if the first line starts with a `>' it ends up getting
      > skipped, which is probably not what you want.
      >
      > The most straightforward (but much too often overlooked, sadly) way to
      > do this is just putting what you want as an Ex line address:
      >
      > 0;/^>/
      >
      > In PlainEnglish[tm], that means "starting from line 0, search for the
      > first line starting with `>', and leave the cursor there". It's so
      > short and simple that it doesn't warrant being wrapped in a function,
      > IMHO.
      >
      >
      > [1] IOW, as four key-presses: `<', `C', `r', and `>'. The first two
      > chars result in an error (`C' is not a motion or a count), so the
      > rest get aborted.

      Hi Piet!

      Works perfectly! Thanks a lot!

      Klaus
    • Tim Chase
      ... for the lazy ones in the crowd like myself, it seems to work fine without the trailing slash. that one extra character can be a drag ;-) This even has
      Message 2 of 10 , Oct 31 2:00 PM
        > The most straightforward (but much too often overlooked, sadly) way to
        > do this is just putting what you want as an Ex line address:
        >
        > 0;/^>/

        for the lazy ones in the crowd like myself, it seems to work fine without
        the trailing slash. that one extra character can be a drag ;-) This even
        has the nice advantage that it catches a > as the first character in a
        file. Using gg/^> won't find that. (okay, so what you really need to do
        for that one is to have search-wrapping on, and G$/^> to find the first
        one in the file)

        -tim
      • kbosau@web.de
        ... Hi Tim, thanks for the explanation! I m a member this crowd too, so I simply added normal G$/^ to the function body and it turned out to work fine now.
        Message 3 of 10 , Nov 1, 2002
          On 31 Oct 2002 at 16:00, Tim Chase wrote:

          > > The most straightforward (but much too often overlooked, sadly) way to
          > > do this is just putting what you want as an Ex line address:
          > >
          > > 0;/^>/
          >
          > for the lazy ones in the crowd like myself, it seems to work fine without
          > the trailing slash. that one extra character can be a drag ;-) This even
          > has the nice advantage that it catches a > as the first character in a
          > file. Using gg/^> won't find that. (okay, so what you really need to do
          > for that one is to have search-wrapping on, and G$/^> to find the first
          > one in the file)

          Hi Tim, thanks for the explanation! I'm a member this crowd too, so I
          simply added "normal G$/^>" to the function body and it turned out to
          work fine now. Just one question: "search-wrapping"... What do I have
          to do to turn this feature on?

          Klaus
        • Piet Delport
          ... If it works, like you said, then you already have it on, but the relevant setting is wrapscan . I really urge you to reconsider and use the 0;/^ / method,
          Message 4 of 10 , Nov 1, 2002
            On Sat, 02 Nov 2002 at 04:52:30 +0100, kbosau@... wrote:
            > On 31 Oct 2002 at 16:00, Tim Chase wrote:
            >
            >>> The most straightforward (but much too often overlooked, sadly) way to
            >>> do this is just putting what you want as an Ex line address:
            >>>
            >>> 0;/^>/
            >>
            >> for the lazy ones in the crowd like myself, it seems to work fine without
            >> the trailing slash. that one extra character can be a drag ;-) This even
            >> has the nice advantage that it catches a > as the first character in a
            >> file. Using gg/^> won't find that. (okay, so what you really need to do
            >> for that one is to have search-wrapping on, and G$/^> to find the first
            >> one in the file)
            >
            > Hi Tim, thanks for the explanation! I'm a member this crowd too, so I
            > simply added "normal G$/^>" to the function body and it turned out to
            > work fine now. Just one question: "search-wrapping"... What do I have
            > to do to turn this feature on?

            If it works, like you said, then you already have it on, but the
            relevant setting is 'wrapscan'.

            I really urge you to reconsider and use the 0;/^>/ method, though. It's
            shorter, simpler, doesn't depend on 'wrapscan' being on, and will work
            even in vanilla Vi (and/or Vim compiled without +ex_extra).

            --
            Piet Delport
            Today's subliminal thought is:
          • Gumnos (Tim Chase)
            ... The germane option is wrapscan (:he ws) Depending on where you re doing this, there are times for both the G/^ and the ex version of :0;/^ I d use the
            Message 5 of 10 , Nov 2, 2002
              > Hi Tim, thanks for the explanation! I'm a member this crowd too, so I
              > simply added "normal G$/^>" to the function body and it turned out to
              > work fine now. Just one question: "search-wrapping"... What do I have
              > to do to turn this feature on?

              The germane option is "wrapscan" (:he ws)

              Depending on where you're doing this, there are times for both the G/^> and
              the ex version of :0;/^> I'd use the former when doing it by hand (while
              editing a document), and use the latter when putting it in a script. The
              latter is also more likely faster (not that it matters much for the trivial
              few cycles of processor difference that occur), as well as shorter to type
              in a script (no need to "normal" it). IIRC, wrapscan defaults to being on
              in vim, though I'm not sure about vanilla vi's behavior in this matter. I
              first learned about the G/^> from the fabulous tutorial (that not only
              teaches the basics like many sites do, but includes a number of great tips,
              tricks, hints, and crazy stunts one can pull off in vi) found at
              http://www.networkcomputing.com/unixworld/tutorial/009/009.html

              particularly, Part 4 on the substitute command. All good stuff :) hth

              -tim
            • kbosau@web.de
              ... Hi Tim! It s really fabulous. I didn t know this site yet but I guess everybody using this editor, for whatever reasons, should know this source. Already
              Message 6 of 10 , Nov 3, 2002
                On 2 Nov 2002 at 9:20, Gumnos (Tim Chase) wrote:

                > > Hi Tim, thanks for the explanation! I'm a member this crowd too, so I
                > > simply added "normal G$/^>" to the function body and it turned out to
                > > work fine now. Just one question: "search-wrapping"... What do I have
                > > to do to turn this feature on?
                >
                > The germane option is "wrapscan" (:he ws)
                >
                > Depending on where you're doing this, there are times for both the G/^> and
                > the ex version of :0;/^> I'd use the former when doing it by hand (while
                > editing a document), and use the latter when putting it in a script. The
                > latter is also more likely faster (not that it matters much for the trivial
                > few cycles of processor difference that occur), as well as shorter to type
                > in a script (no need to "normal" it). IIRC, wrapscan defaults to being on
                > in vim, though I'm not sure about vanilla vi's behavior in this matter. I
                > first learned about the G/^> from the fabulous tutorial (that not only
                > teaches the basics like many sites do, but includes a number of great tips,
                > tricks, hints, and crazy stunts one can pull off in vi) found at
                > http://www.networkcomputing.com/unixworld/tutorial/009/009.html

                Hi Tim!

                It's really fabulous. I didn't know this site yet but I guess
                everybody using this editor, for whatever reasons, should know
                this source. Already bookmarked...

                Thanks for the hint!

                Klaus

                PS: The email extension I worked on is now ready and it turned
                out to be very comfortable. Unfortunately not every email/news-
                client offers a comfortable way to involve an external editor,
                though most of the inbuilt ones are not even able to do the
                simplest things. Pegasus for instance, a mail program with,
                definitely, the most crappy editing extension I ever saw. Try
                out and you'll start to love even "notepad"... :-) Bye!
              Your message has been successfully submitted and would be delivered to recipients shortly.