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

Strange pattern matches for \_.*

Expand Messages
  • Dimitar DIMITROV
    Hi all, Not sure why / _.* matches at every line Vs only once... I would expect a single match at start of file because _. matches any char including end of
    Message 1 of 6 , Jul 26, 2013
      Hi all,

      Not sure why /\_.* matches at every line Vs only once...
      I would expect a single match at start of file because \_. matches any char including end of line and * is greedy
      /pattern\_.* does what I expect: it matches from pattern to end of file
       
      Dimitar


      ---
      GPG Key: 2048R/160C6FA8 2012-10-11 Dimitar Dimitrov (kurkale6ka) <mitkofr@...>

      --
      --
      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
       
      ---
      You received this message because you are subscribed to the Google Groups "vim_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
       
       
    • Dimitar DIMITROV
      ... didn t explain it well in my above statement is the behaviour of n, N. /, :/ So, n goes to every line Vs stay at the first byte of the file and never move
      Message 2 of 6 , Jul 29, 2013
        > Hi all,
        >
        > Not sure why /\_.* matches at every line Vs only once...
        > I would expect a single match at start of file because \_. matches any char including end of line and * is greedy
        > /pattern\_.* does what I expect: it matches from pattern to end of file
        >
        > Dimitar

        An update/clarification on this:

        :%s/\_.* does correctly erase the whole file. What is actually incorrect and I
        didn't explain it well in my above statement is the behaviour of n, N. /, :/
        So, n goes to every line Vs stay at the first byte of the file and never move
         
        Dimitar

        ---
        GPG Key: 2048R/160C6FA8 2012-10-11 Dimitar Dimitrov (kurkale6ka) <mitkofr@...>

        --
        --
        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
         
        ---
        You received this message because you are subscribed to the Google Groups "vim_dev" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
         
         
      • Christian Brabandt
        ... I think this is correct. _.* doesn t say, Vim should start matching only at the start of the file, so Vim will try matching at each line again. I think,
        Message 3 of 6 , Jul 29, 2013
          On Mon, July 29, 2013 14:59, Dimitar DIMITROV wrote:
          >> Hi all,
          >>
          >> Not sure why /\_.* matches at every line Vs only once...
          >> I would expect a single match at start of file because \_. matches any
          >> char including end of line and * is greedy
          >> /pattern\_.* does what I expect: it matches from pattern to end of file
          >>
          >> Dimitar
          >
          > An update/clarification on this:
          >
          > :%s/\_.* does correctly erase the whole file. What is actually incorrect
          > and I
          > didn't explain it well in my above statement is the behaviour of n, N. /,
          > :/
          > So, n goes to every line Vs stay at the first byte of the file and never
          > move

          I think this is correct. \_.* doesn't say, Vim should start matching only
          at the start of the file, so Vim will try matching at each line again.

          I think, Vim has always done this and restarted trying to match
          after linebreaks.

          If you want to keep matching at the start of the file, use the \%^ atom.

          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

          ---
          You received this message because you are subscribed to the Google Groups "vim_dev" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Dimitar DIMITROV
          ... I disagree, following your logic, after /lorem _.*ipsum and the following file: lorem ipsum n would move us to both lines which is not correct The point is
          Message 4 of 6 , Jul 29, 2013
            > >> Hi all,
            > >>
            > >> Not sure why /\_.* matches at every line Vs only once...
            > >> I would expect a single match at start of file because \_. matches any
            > >> char including end of line and * is greedy
            > >> /pattern\_.* does what I expect: it matches from pattern to end of file
            > >>
            > >> Dimitar
            > >
            > > An update/clarification on this:
            > >
            > > :%s/\_.* does correctly erase the whole file. What is actually incorrect
            > > and I
            > > didn't explain it well in my above statement is the behaviour of n, N. /,
            > > :/
            > > So, n goes to every line Vs stay at the first byte of the file and never
            > > move
            >
            > I think this is correct. \_.* doesn't say, Vim
            should start matching only
            > at the start of the file, so Vim will try matching at each line again.

            I disagree, following your logic, after /lorem\_.*ipsum and the following file:

            lorem
            ipsum

            n would move us to both lines which is not correct

            The point is not about matching at the start of the file. What I am saying is, because there is only one match, that's what should happen.

            > I think, Vim has always done this and restarted trying to match
            > after linebreaks.
            >
            > If you want to keep matching at the start of the file, use the \%^ atom.
            >
            > regards,
            > Christian
             
            Dimitar

            ---
            GPG Key: 2048R/160C6FA8 2012-10-11 Dimitar Dimitrov (kurkale6ka) <mitkofr@...>

            --
            --
            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
             
            ---
            You received this message because you are subscribed to the Google Groups "vim_dev" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
             
             
          • Christian Brabandt
            ... Of course not. the lorem part doesn t match at the next line (ipsum). Try this example: aann nnbb and search for /n _[n]* hitting n will move you to the
            Message 5 of 6 , Jul 29, 2013
              On Mon, July 29, 2013 16:14, Dimitar DIMITROV wrote:
              >> >> Hi all,
              >> >>
              >> >> Not sure why /\_.* matches at every line Vs only once...
              >> >> I would expect a single match at start of file because \_. matches
              >> any
              >> >> char including end of line and * is greedy
              >> >> /pattern\_.* does what I expect: it matches from pattern to end of
              >> file
              >> >>
              >> >> Dimitar
              >> >
              >> > An update/clarification on this:
              >> >
              >> > :%s/\_.* does correctly erase the whole file. What is actually
              >> incorrect
              >> > and I
              >> > didn't explain it well in my above statement is the behaviour of n, N.
              >> /,
              >> > :/
              >> > So, n goes to every line Vs stay at the first byte of the file and
              >> never
              >> > move
              >>
              >> I think this is correct. \_.* doesn't say, Vim should start matching
              >> only
              >> at the start of the file, so Vim will try matching at each line again.
              >
              > I disagree, following your logic, after /lorem\_.*ipsum and the following
              > file:
              >
              > lorem
              > ipsum
              >
              > n would move us to both lines which is not correct

              Of course not. the lorem part doesn't match at the next line (ipsum).

              Try this example:

              aann
              nnbb

              and search for
              /n\_[n]*

              hitting n will move you to the next line.


              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

              ---
              You received this message because you are subscribed to the Google Groups "vim_dev" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • Dimitar DIMITROV
              ... All I am trying to say is that this is a *single* match (/n _[n]* matches *all* n in your example) so a single n move would make more sense, same as in
              Message 6 of 6 , Jul 29, 2013
                > >> >> Hi all,
                > >> >>
                > >> >> Not sure why /\_.* matches at every line Vs only once...
                > >> >> I would expect a single match at start of file because \_. matches
                > >> any
                > >> >> char including end of line and * is greedy
                > >> >> /pattern\_.* does what I expect: it matches from pattern to end of
                > >> file
                > >> >>
                > >> >> Dimitar
                > >> >
                > >> > An update/clarification on this:
                > >> >
                > >> > :%s/\_.* does correctly erase the whole file. What is actually
                > >> incorrect
                > >> > and I
                > >> > didn't explain it well in my above statement is the behaviour of n, N.
                > >> /,
                > >> > :/
                > >> > So, n goes to every line Vs stay at the first byte of the file and
                > >> never
                > >> > move
                > >>
                > >> I think this is correct. \_.* doesn't say, Vim should start matching
                > >> only
                > >> at the start of the file, so Vim will try matching at each line again.
                > >
                > > I disagree, following your logic, after /lorem\_.*ipsum and the following
                > > file:
                > >
                > > lorem
                > > ipsum
                > >
                > > n would move us to both lines which is not correct
                >
                > Of course not. the lorem part doesn't match at the next line (ipsum).
                > Try this example:
                >
                > aann
                > nnbb
                >
                > and search for
                > /n\_[n]*

                All I am trying to say is that this is a *single* match (/n\_[n]* matches *all* n in your example) so a single n move would make more sense,
                same as in this non-multiline pattern: aaaaaaaaaaaaaa, /a* is a single match and n won't move once for every letter

                > hitting n will move you to the next line.
                >
                >
                > regards,
                > Christian
                 
                Dimitar

                ---
                GPG Key: 2048R/160C6FA8 2012-10-11 Dimitar Dimitrov (kurkale6ka) <mitkofr@...>

                --
                --
                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
                 
                ---
                You received this message because you are subscribed to the Google Groups "vim_dev" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
                For more options, visit https://groups.google.com/groups/opt_out.
                 
                 
              Your message has been successfully submitted and would be delivered to recipients shortly.