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

Searching for next place where pattern does *not* match?

Expand Messages
  • Jean Jordaan
    Hi all On a file like: ap*acs29_sink apacs29_sink ^apacs29_src Cursor is at *. I want it to go to ^. (* and ^ do not appear in the file, they re just to show
    Message 1 of 6 , Dec 7, 2000
    • 0 Attachment
      Hi all

      On a file like:

      ap*acs29_sink
      apacs29_sink
      ^apacs29_src

      Cursor is at *. I want it to go to ^. (* and ^ do not appear in the
      file, they're just to show the cursor.)

      This search works:
      /[^\(apacs29_sink\)]
      but this one doesn't:
      /^[^\(apacs29_sink\)]

      The general question is: How do I find the next line that *doesn't*
      start with the same pattern as the current one?

      --
      Jean Jordaan -- technical writer -- Mosaic Software
    • Benji Fisher
      ... I think you misunderstand what the [brackets] are doing. In particular, there is no special meaning for ( ) inside the brackets: these are just four
      Message 2 of 6 , Dec 7, 2000
      • 0 Attachment
        Jean Jordaan wrote:
        >
        > Hi all
        >
        > On a file like:
        >
        > ap*acs29_sink
        > apacs29_sink
        > ^apacs29_src
        >
        > Cursor is at *. I want it to go to ^. (* and ^ do not appear in the
        > file, they're just to show the cursor.)
        >
        > This search works:
        > /[^\(apacs29_sink\)]
        > but this one doesn't:
        > /^[^\(apacs29_sink\)]
        >
        > The general question is: How do I find the next line that *doesn't*
        > start with the same pattern as the current one?

        I think you misunderstand what the [brackets] are doing. In
        particular, there is no special meaning for \(\) inside the brackets:
        these are just four characters. Re-read :help /[] (and search for "NOTE").

        In vim 6.0, there is a way to do what you want with a regular
        expression. In vim 5.7 (or earlier) the only way is to do something
        horrendous like

        / ^$ \| ^[^a] \| ^a$ \| ^a[^p] \| ^ap$ \| ^ap[^a] ...

        (The spaces are there for ease of reading; do not really use them in a
        search pattern.)

        Who says we have to solve this problem using just regular expressions?

        :let found_it = 0
        :.,$v/^apacs29_sink/if !found_it|let next=line('.')|let found_it=1|endif
        :if found_it | execute next | endif

        This would be very slow on a large file, but it should work. If you are
        doing this by hand, not from a function or mapping, you might consider
        yanking the desired expression, then

        :set hls " if it is not already set
        /^<C-R>".*

        and then looking for the first line that is not highlighted.

        HTH --Benji Fisher
      • Jean Jordaan
        Hi Benji ... Yes .. wishful thinking, on my part .. ... Well, it makes me feel a little better that I wasn t overlooking something obvious. ... Wow, rather
        Message 3 of 6 , Dec 7, 2000
        • 0 Attachment
          Hi Benji

          > I think you misunderstand what the [brackets] are doing.

          Yes .. wishful thinking, on my part ..

          > In vim 5.7 (or earlier) the only way is to do something horrendous

          Well, it makes me feel a little better that I wasn't overlooking
          something obvious.

          > :let found_it = 0
          > :.,$v/^apacs29_sink/if !found_it|let next=line('.')|let found_it=1|endif
          > :if found_it | execute next | endif

          Wow, rather sublime .. I love that feeling when I grok something like
          this for the first time .. thanks!

          jean
          --
          The only thing worse than raining cats and dogs is hailing taxis.
        • Andrzej M. Ostruszka
          ... My main point is that there is no :break (or similary named function) that would cause breaking :g and :v. I hope I missed it in docs but I don t think
          Message 4 of 6 , Dec 8, 2000
          • 0 Attachment
            On Fri, Dec 08 (2000), Jean Jordaan wrote:
            > > :let found_it = 0
            > > :.,$v/^apacs29_sink/if !found_it|let next=line('.')|let found_it=1|endif
            > > :if found_it | execute next | endif
            >
            > Wow, rather sublime .. I love that feeling when I grok something like
            > this for the first time .. thanks!

            It would have been nicer if one could write something like:

            :.,$v/^apacs29_sink/break

            My main point is that there is no :break (or similary named function)
            that would cause breaking :g and :v. I hope I missed it in docs but I
            don't think this is the case -- if so this is my suggestion :)).

            Best regards
            --
            ____ _ ___
            / | \_/ |/ _ \ Andrzej Marek Ostruszka
            / _ | | (_) | Instytut Fizyki, Uniwersytet Jagiellonski (Cracow)
            /_/ L|_|V|_|\___/ (PGP <-- finger ostruszk@...)
          • c928400@student.dtu.dk
            ... That would probably only be included in the development releases (for now, of course :-), But then again, there is already ... Peppe -- Before you
            Message 5 of 6 , Dec 8, 2000
            • 0 Attachment
              Thus wrote Andrzej M. Ostruszka (ostruszk@...) on [001208]:
              > It would have been nicer if one could write something like:

              > :.,$v/^apacs29_sink/break

              > My main point is that there is no :break (or similary named function)
              > that would cause breaking :g and :v. I hope I missed it in docs but I
              > don't think this is the case -- if so this is my suggestion :)).

              That would probably only be included in the development releases (for
              now, of course :-),

              But then again, there is already

              :call search('^apacs29_sink', 0)

              Peppe
              --
              "Before you criticize someone, walk
              Preben "Peppe" Guldberg __/-\__ a mile in his shoes. That way, if
              c928400@... (o o) he gets angry, he'll be a mile away
              ----------------------oOOo (_) oOOo-- - and barefoot." --Sarah Jackson
            • Benji Fisher
              ... Yes, and (according to http://www.vim.org/docnew/version6.txt, look for new-searchpat) vim 6.0 will also allow (if I have the syntax right)
              Message 6 of 6 , Dec 8, 2000
              • 0 Attachment
                c928400@... wrote:
                >
                > Thus wrote Andrzej M. Ostruszka (ostruszk@...) on [001208]:
                > > It would have been nicer if one could write something like:
                >
                > > :.,$v/^apacs29_sink/break
                >
                > > My main point is that there is no :break (or similary named function)
                > > that would cause breaking :g and :v. I hope I missed it in docs but I
                > > don't think this is the case -- if so this is my suggestion :)).
                >
                > That would probably only be included in the development releases (for
                > now, of course :-),
                >
                > But then again, there is already
                >
                > :call search('^apacs29_sink', 0)
                >
                > Peppe

                Yes, and (according to http://www.vim.org/docnew/version6.txt, look
                for new-searchpat) vim 6.0 will also allow (if I have the syntax right)

                /^\(apacs29_sink\)\@!

                With vim 5.7, there is always the option of an explicit loop:

                let curline = line(".") - 1
                while curline < line("$")
                let curline = curline + 1
                if getline(curline) !~ '^apacs29_sink'
                echo "found it!"
                execute curline
                break
                endif
                endwhile

                (untested).

                Then again, one can always try cleverness:

                .,$v/^apacs29_sink/call input('Enter <C-C>')

                (Heh, heh!) --Benji Fisher
              Your message has been successfully submitted and would be delivered to recipients shortly.