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

search results depend on length

Expand Messages
  • Thilo Six
    Hello attached is a example file. When searching in there with: /vi |vim or /vim |vi does not give the same results. Which is what i would expect. Actually the
    Message 1 of 17 , Oct 29, 2011
    • 0 Attachment
      Hello

      attached is a example file. When searching in there with:
      /vi\|vim
      or
      /vim\|vi

      does not give the same results. Which is what i would expect.
      Actually the latter gives the results i was vim asking for.
      My vim version is a bit dated though: 7.2.445 .
      Or am i doing something wrong?

      --
      Regards,
      Thilo

      4096R/0xC70B1A8F
      721B 1BA0 095C 1ABA 3FC6 7C18 89A4 A2A0 C70B 1A8F

      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Ivan Krasilnikov
      ... This is the intended behavior. From :help regexp: A pattern is one or more branches, separated by | . ... If more than one branch matches, the first one
      Message 2 of 17 , Oct 29, 2011
      • 0 Attachment
        2011/10/29 Thilo Six <T.Six@...>:
        > attached is a example file. When searching in there with:
        > /vi\|vim
        > or
        > /vim\|vi
        >
        > does not give the same results. Which is what i would expect.

        This is the intended behavior. From :help regexp:
        "A pattern is one or more branches, separated by "\|". ...
        If more than one branch matches, the first one is used."

        So, /vi\|vim is same as /vi.

        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Thilo Six
        Ivan Krasilnikov wrote the following on 29.10.2011 15:55 Hello Ivan, -- -- ... Thank you for the pointers. I need to mentally keep a note about that for
        Message 3 of 17 , Oct 29, 2011
        • 0 Attachment
          Ivan Krasilnikov wrote the following on 29.10.2011 15:55

          Hello Ivan,

          -- <snip> --
          > This is the intended behavior. From :help regexp:
          > "A pattern is one or more branches, separated by "\|". ...
          > If more than one branch matches, the first one is used."
          >
          > So, /vi\|vim is same as /vi.

          Thank you for the pointers.
          I need to mentally keep a note about that for future.

          --
          Regards,
          Thilo

          4096R/0xC70B1A8F
          721B 1BA0 095C 1ABA 3FC6 7C18 89A4 A2A0 C70B 1A8F


          --
          You received this message from the "vim_dev" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Thilo Six
          Thilo Six wrote the following on 29.10.2011 16:07 hello, -- -- ... ,----[ :help regexp ]------------------------- If more than one branch matches, the
          Message 4 of 17 , Oct 29, 2011
          • 0 Attachment
            Thilo Six wrote the following on 29.10.2011 16:07

            hello,

            -- <snip> --

            >> So, /vi\|vim is same as /vi.
            >
            > Thank you for the pointers.
            > I need to mentally keep a note about that for future.


            ,----[ :help regexp ]-------------------------

            If more than one branch matches, the first one is used.
            `---------------------------------------------

            I don't speak c, so why is there the limitation mentioned above?
            It can't be for performance because both searches are equally fast (humanly
            speaking). But it breaks expectations as i tell vim to search for 'vi' OR 'vim'
            in both cases.
            Maybe if i understand the technical background i get more used to it.

            --
            Regards,
            Thilo

            4096R/0xC70B1A8F
            721B 1BA0 095C 1ABA 3FC6 7C18 89A4 A2A0 C70B 1A8F


            --
            You received this message from the "vim_dev" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • James McCoy
            ... This is a common design choice for regular expressions. The left-most pattern that matches is what is used. You ll see similar behavior with PCRE: $
            Message 5 of 17 , Oct 29, 2011
            • 0 Attachment
              On Sat, Oct 29, 2011 at 2:04 PM, Thilo Six <T.Six@...> wrote:
              > Thilo Six wrote the following on 29.10.2011 16:07
              >
              > hello,
              >
              > -- <snip> --
              >
              >>> So, /vi\|vim is same as /vi.
              >>
              >> Thank you for the pointers.
              >> I need to mentally keep a note about that for future.
              >
              >
              > ,----[ :help regexp ]-------------------------
              >
              > If more than one branch matches, the first one is used.
              > `---------------------------------------------
              >
              > I don't speak c, so why is there the limitation mentioned above?
              > It can't be for performance because both searches are equally fast (humanly
              > speaking).

              This is a common design choice for regular expressions. The left-most
              pattern that matches is what is used. You'll see similar behavior
              with PCRE:

              $ printf "vim\n" | perl -pe '/(vi|vim)/ && print "$1\n"'
              vi

              > But it breaks expectations as i tell vim to search for 'vi' OR 'vim'
              > in both cases.
              > Maybe if i understand the technical background i get more used to it.

              In this specific example, sure it's not that much more work to use the
              longest of the two patterns as THE match, but this is a trivial case.
              You can have much more complicated patterns and multiple alternations.
              Then do you really want to have the regex engine try all the
              alternations just to find the one that's matches the most text and is
              that really what you want in that specific scenario? It's much easier
              to just change the regular expression to do what you want with the
              understanding of how regular expressions are used.

              I'd suggest the book "Mastering Regular Expressions". It does a
              pretty good job of explaining how various regular expression engines
              work and things to keep in mind when crafting regular expressions.

              --
              James
              GPG Key: 1024D/61326D40 2003-09-02 James McCoy <jamessan@...>

              --
              You received this message from the "vim_dev" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • Thilo Six
              James McCoy wrote the following on 29.10.2011 20:25 Konichiwa James San, -- -- ... Thats why i asked again. Thank you very much for the explanation. ...
              Message 6 of 17 , Oct 29, 2011
              • 0 Attachment
                James McCoy wrote the following on 29.10.2011 20:25

                Konichiwa James San,

                -- <snip> --
                > It's much easier
                > to just change the regular expression to do what you want with the
                > understanding of how regular expressions are used.

                Thats why i asked again. Thank you very much for the explanation.

                > I'd suggest the book "Mastering Regular Expressions". It does a
                > pretty good job of explaining how various regular expression engines
                > work and things to keep in mind when crafting regular expressions.

                I'll do my best.
                --
                Regards,
                Thilo

                4096R/0xC70B1A8F
                721B 1BA0 095C 1ABA 3FC6 7C18 89A4 A2A0 C70B 1A8F


                --
                You received this message from the "vim_dev" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
              • Tony Mechelynck
                ... vi always matches wherever vim matches, so you have a kind of degenerate case here. Maybe what you wanted was /vi %[m] or /vim = See ... Best regards,
                Message 7 of 17 , Oct 30, 2011
                • 0 Attachment
                  On 29/10/11 11:22, Thilo Six wrote:
                  > Hello
                  >
                  > attached is a example file. When searching in there with:
                  > /vi\|vim
                  > or
                  > /vim\|vi
                  >
                  > does not give the same results. Which is what i would expect.
                  > Actually the latter gives the results i was vim asking for.
                  > My vim version is a bit dated though: 7.2.445 .
                  > Or am i doing something wrong?
                  >

                  "vi" always matches wherever "vim" matches, so you have a kind of
                  degenerate case here.

                  Maybe what you wanted was

                  /vi\%[m]

                  or

                  /vim\=

                  See
                  :help /\=
                  :help /\%[]


                  Best regards,
                  Tony.
                  --
                  hundred-and-one symptoms of being an internet addict:
                  207. Your given you one phone call in prison and you ask them for a laptop.

                  --
                  You received this message from the "vim_dev" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php
                • Thilo Six
                  Tony Mechelynck wrote the following on 31.10.2011 00:08 Hello Tony, -- -- ... Thanks for the pointer. There are quite a lot of search atoms. Although
                  Message 8 of 17 , Oct 31, 2011
                  • 0 Attachment
                    Tony Mechelynck wrote the following on 31.10.2011 00:08

                    Hello Tony,

                    -- <snip> --

                    > "vi" always matches wherever "vim" matches, so you have a kind of
                    > degenerate case here.
                    >
                    > Maybe what you wanted was
                    >
                    > /vi\%[m]
                    >
                    > or
                    >
                    > /vim\=
                    >
                    > See
                    > :help /\=
                    > :help /\%[]
                    >
                    >
                    > Best regards,
                    > Tony.

                    Thanks for the pointer. There are quite a lot of search atoms. Although i'll
                    always try to look at 'pattern-atoms' i obviously have to learn.
                    Which is quite fun sometimes. It is like playing vim-chess. Kind of.
                    But it is quite a lot less fun if you are in hurry have to achieve something by
                    date.

                    Thank you.
                    --
                    Regards,
                    Thilo

                    4096R/0xC70B1A8F
                    721B 1BA0 095C 1ABA 3FC6 7C18 89A4 A2A0 C70B 1A8F


                    --
                    You received this message from the "vim_dev" maillist.
                    Do not top-post! Type your reply below the text you are replying to.
                    For more information, visit http://www.vim.org/maillist.php
                  • Ernie Rael
                    ... Off topic, but I ve been wondering... Is there an option to use perl/python syntax for RE? If not, would that be a welcome patch? Could it be done with
                    Message 9 of 17 , Oct 31, 2011
                    • 0 Attachment
                      On 10/31/2011 10:31 AM, Thilo Six wrote:
                      > Tony Mechelynck wrote the following on 31.10.2011 00:08
                      >
                      > Hello Tony,
                      >
                      > -- <snip> --
                      >
                      >> "vi" always matches wherever "vim" matches, so you have a kind of
                      >> degenerate case here.
                      >>
                      >> Maybe what you wanted was
                      >>
                      >> /vi\%[m]
                      >>
                      >> or
                      >>
                      >> /vim\=
                      >>
                      >> See
                      >> :help /\=
                      >> :help /\%[]
                      >>
                      >>
                      >> Best regards,
                      >> Tony.
                      > Thanks for the pointer. There are quite a lot of search atoms. Although i'll
                      > always try to look at 'pattern-atoms' i obviously have to learn.
                      > Which is quite fun sometimes. It is like playing vim-chess. Kind of.
                      > But it is quite a lot less fun if you are in hurry have to achieve something by
                      > date.
                      >
                      > Thank you.
                      Off topic, but I've been wondering...

                      Is there an option to use perl/python syntax for RE? If not, would that
                      be a welcome patch? Could it be done with vim's scripting? Also an
                      optional string which indicates which chars need escaping (like ')' or
                      '?') might be useful.

                      -ernie

                      --
                      You received this message from the "vim_dev" maillist.
                      Do not top-post! Type your reply below the text you are replying to.
                      For more information, visit http://www.vim.org/maillist.php
                    • Ingo Karkat
                      ... Both have unique constructs, cp. :help perl-patterns. ... Unless I misunderstand, isn t that achieved through changing the magic-ness of a pattern: v V
                      Message 10 of 17 , Oct 31, 2011
                      • 0 Attachment
                        On 31-Oct-2011 20:37, Ernie Rael wrote:

                        > Off topic, but I've been wondering...
                        >
                        > Is there an option to use perl/python syntax for RE? If not, would that be a
                        > welcome patch? Could it be done with vim's scripting?

                        Both have unique constructs, cp. :help perl-patterns.

                        > Also an optional string which indicates which chars need escaping
                        > (like ')' or '?') might be useful.

                        Unless I misunderstand, isn't that achieved through changing the magic-ness of a
                        pattern: \v \V \m \M ?!

                        -- regards, ingo

                        --
                        You received this message from the "vim_dev" maillist.
                        Do not top-post! Type your reply below the text you are replying to.
                        For more information, visit http://www.vim.org/maillist.php
                      • Ernie Rael
                        ... True. I am willing to give up the vim only features and the perl only features to use a syntax I already use a lot (a syntax which is also the base of the
                        Message 11 of 17 , Oct 31, 2011
                        • 0 Attachment
                          On 10/31/2011 12:53 PM, Ingo Karkat wrote:
                          > On 31-Oct-2011 20:37, Ernie Rael wrote:
                          >
                          >> Off topic, but I've been wondering...
                          >>
                          >> Is there an option to use perl/python syntax for RE? If not, would that be a
                          >> welcome patch? Could it be done with vim's scripting?
                          > Both have unique constructs, cp. :help perl-patterns.
                          True. I am willing to give up the vim only features and the perl only
                          features to use a syntax I already use a lot (a syntax which is also the
                          base of the java syntax).
                          >
                          >> Also an optional string which indicates which chars need escaping
                          >> (like ')' or '?') might be useful.
                          > Unless I misunderstand, isn't that achieved through changing the magic-ness of a
                          > pattern: \v \V \m \M ?!
                          It's similar, but a list of chars that need escaping is more flexible. I
                          could specify that '(' needs to be escaped to mean grouping and that '?'
                          does not need to be escaped to mean optional. Using the list could be
                          dependent on the "magic-ness of a pattern".
                          >
                          > -- regards, ingo
                          >

                          --
                          You received this message from the "vim_dev" maillist.
                          Do not top-post! Type your reply below the text you are replying to.
                          For more information, visit http://www.vim.org/maillist.php
                        • Tony Mechelynck
                          On 31/10/11 18:31, Thilo Six wrote: [...] ... sheet starting at |pattern-overview|, which might be easier to consult. Best regards, Tony. -- A day for firm
                          Message 12 of 17 , Oct 31, 2011
                          • 0 Attachment
                            On 31/10/11 18:31, Thilo Six wrote:
                            [...]
                            > Thanks for the pointer. There are quite a lot of search atoms. Although i'll
                            > always try to look at 'pattern-atoms' i obviously have to learn.
                            > Which is quite fun sometimes. It is like playing vim-chess. Kind of.
                            > But it is quite a lot less fun if you are in hurry have to achieve something by
                            > date.
                            >
                            > Thank you.

                            |pattern-atoms| is the encyclopaedic treatment. There is also a cheat
                            sheet starting at |pattern-overview|, which might be easier to consult.


                            Best regards,
                            Tony.
                            --
                            A day for firm decisions!!!!! Or is it?

                            --
                            You received this message from the "vim_dev" maillist.
                            Do not top-post! Type your reply below the text you are replying to.
                            For more information, visit http://www.vim.org/maillist.php
                          • Thilo Six
                            Tony Mechelynck wrote the following on 31.10.2011 21:31 Hello Tony, -- -- ... Thanks again. -- Regards, Thilo 4096R/0xC70B1A8F 721B 1BA0 095C 1ABA 3FC6
                            Message 13 of 17 , Oct 31, 2011
                            • 0 Attachment
                              Tony Mechelynck wrote the following on 31.10.2011 21:31

                              Hello Tony,

                              -- <snip> --

                              > |pattern-atoms| is the encyclopaedic treatment. There is also a cheat
                              > sheet starting at |pattern-overview|, which might be easier to consult.
                              >
                              >
                              > Best regards,
                              > Tony.

                              Thanks again.

                              --
                              Regards,
                              Thilo

                              4096R/0xC70B1A8F
                              721B 1BA0 095C 1ABA 3FC6 7C18 89A4 A2A0 C70B 1A8F


                              --
                              You received this message from the "vim_dev" maillist.
                              Do not top-post! Type your reply below the text you are replying to.
                              For more information, visit http://www.vim.org/maillist.php
                            • Christian Brabandt
                              ... Hm, interesting concept. Attached is a simple script to try out. Use ... to specify which chars have a special meaning and don t need to be escaped (only
                              Message 14 of 17 , Oct 31, 2011
                              • 0 Attachment
                                On Mo, 31 Okt 2011, Ernie Rael wrote:

                                > It's similar, but a list of chars that need escaping is more flexible.
                                > I could specify that '(' needs to be escaped to mean grouping and that
                                > '?' does not need to be escaped to mean optional. Using the list could
                                > be dependent on the "magic-ness of a pattern".

                                Hm, interesting concept. Attached is a simple script to try out.

                                Use
                                :let g:re_dont_escape = '()|?'
                                to specify which chars have a special meaning and don't need to be
                                escaped (only for using the literal version). So in this example, '()
                                wouldn't need to be escaped for grouping, '|' means OR and '?' means
                                optional match.

                                When searching, press <f7> to translate the pattern into a vim pattern.
                                It basically only adds/removes the backslashes (so you need to know all
                                vim specific atoms, like '\@<=' and can't use e.g. Perl look-arounds).

                                Disclaimer, only very basically tested.

                                regards,
                                Christian

                                --
                                You received this message from the "vim_dev" maillist.
                                Do not top-post! Type your reply below the text you are replying to.
                                For more information, visit http://www.vim.org/maillist.php
                              • Andy Wokula
                                ... Neat! attached is a mod with backslash/ ff -bugs fixed and simpler notation, shorter gen d patterns and preparation for multi-char items, otherwise no
                                Message 15 of 17 , Nov 1, 2011
                                • 0 Attachment
                                  Am 31.10.2011 22:59, schrieb Christian Brabandt:
                                  > On Mo, 31 Okt 2011, Ernie Rael wrote:
                                  >
                                  >> It's similar, but a list of chars that need escaping is more flexible.
                                  >> I could specify that '(' needs to be escaped to mean grouping and that
                                  >> '?' does not need to be escaped to mean optional. Using the list could
                                  >> be dependent on the "magic-ness of a pattern".
                                  >
                                  > Hm, interesting concept. Attached is a simple script to try out.
                                  >
                                  > Use
                                  > :let g:re_dont_escape = '()|?'
                                  > to specify which chars have a special meaning and don't need to be
                                  > escaped (only for using the literal version). So in this example, '()
                                  > wouldn't need to be escaped for grouping, '|' means OR and '?' means
                                  > optional match.
                                  >
                                  > When searching, press<f7> to translate the pattern into a vim pattern.
                                  > It basically only adds/removes the backslashes (so you need to know all
                                  > vim specific atoms, like '\@<=' and can't use e.g. Perl look-arounds).
                                  >
                                  > Disclaimer, only very basically tested.
                                  >
                                  > regards,
                                  > Christian

                                  Neat! attached is a mod with backslash/'ff'-bugs fixed and simpler
                                  notation, shorter gen'd patterns and preparation for multi-char items,
                                  otherwise no feats added.

                                  --
                                  Andy

                                  --
                                  You received this message from the "vim_dev" maillist.
                                  Do not top-post! Type your reply below the text you are replying to.
                                  For more information, visit http://www.vim.org/maillist.php
                                • Ernie Rael
                                  ... Thanks Christian and Andy. I m on vacation now, won t be giving this any play until after next week. But it looks like some pros are working it over.
                                  Message 16 of 17 , Nov 1, 2011
                                  • 0 Attachment
                                    On 10/31/2011 2:59 PM, Christian Brabandt wrote:
                                    > On Mo, 31 Okt 2011, Ernie Rael wrote:
                                    >
                                    >> It's similar, but a list of chars that need escaping is more flexible.
                                    >> I could specify that '(' needs to be escaped to mean grouping and that
                                    >> '?' does not need to be escaped to mean optional. Using the list could
                                    >> be dependent on the "magic-ness of a pattern".
                                    > Hm, interesting concept. Attached is a simple script to try out.
                                    >
                                    > Use
                                    > :let g:re_dont_escape = '()|?'
                                    > to specify which chars have a special meaning and don't need to be
                                    > escaped (only for using the literal version). So in this example, '()
                                    > wouldn't need to be escaped for grouping, '|' means OR and '?' means
                                    > optional match.
                                    >
                                    > When searching, press<f7> to translate the pattern into a vim pattern.
                                    > It basically only adds/removes the backslashes (so you need to know all
                                    > vim specific atoms, like '\@<=' and can't use e.g. Perl look-arounds).
                                    >
                                    > Disclaimer, only very basically tested.
                                    >
                                    > regards,
                                    > Christian
                                    >
                                    Thanks Christian and Andy.

                                    I'm on vacation now, won't be giving this any play until after next
                                    week. But it looks like some pros are working it over.

                                    -ernie

                                    --
                                    You received this message from the "vim_dev" maillist.
                                    Do not top-post! Type your reply below the text you are replying to.
                                    For more information, visit http://www.vim.org/maillist.php
                                  • Christian Brabandt
                                    Hi Andy! ... Nice. Here is your version extended by not replacing inside collations. regards, Christian -- -- You received this message from the vim_dev
                                    Message 17 of 17 , Nov 1, 2011
                                    • 0 Attachment
                                      Hi Andy!

                                      On Di, 01 Nov 2011, Andy Wokula wrote:

                                      > Am 31.10.2011 22:59, schrieb Christian Brabandt:
                                      > >On Mo, 31 Okt 2011, Ernie Rael wrote:
                                      > >
                                      > >>It's similar, but a list of chars that need escaping is more flexible.
                                      > >>I could specify that '(' needs to be escaped to mean grouping and that
                                      > >>'?' does not need to be escaped to mean optional. Using the list could
                                      > >>be dependent on the "magic-ness of a pattern".
                                      > >
                                      > >Hm, interesting concept. Attached is a simple script to try out.
                                      > >
                                      > >Use
                                      > >:let g:re_dont_escape = '()|?'
                                      > >to specify which chars have a special meaning and don't need to be
                                      > >escaped (only for using the literal version). So in this example, '()
                                      > >wouldn't need to be escaped for grouping, '|' means OR and '?' means
                                      > >optional match.
                                      > >
                                      > >When searching, press<f7> to translate the pattern into a vim pattern.
                                      > >It basically only adds/removes the backslashes (so you need to know all
                                      > >vim specific atoms, like '\@<=' and can't use e.g. Perl look-arounds).
                                      > >
                                      > >Disclaimer, only very basically tested.
                                      > >
                                      > >regards,
                                      > >Christian
                                      >
                                      > Neat! attached is a mod with backslash/'ff'-bugs fixed and simpler
                                      > notation, shorter gen'd patterns and preparation for multi-char items,
                                      > otherwise no feats added.
                                      >

                                      Nice. Here is your version extended by not replacing inside collations.


                                      regards,
                                      Christian
                                      --

                                      --
                                      You received this message from the "vim_dev" maillist.
                                      Do not top-post! Type your reply below the text you are replying to.
                                      For more information, visit http://www.vim.org/maillist.php
                                    Your message has been successfully submitted and would be delivered to recipients shortly.