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

Re: 1,5s/[^ ]*// or 1,5dw?

Expand Messages
  • Oliver Fuchs
    ... Yes, there has to be a second s like ... to match the whitespace behind the first deleted word. ... Why is now the leading whitespace not deleted. * means
    Message 1 of 18 , Sep 1, 2005
      On Thu, 01 Sep 2005, Tony Mechelynck wrote:

      > ----- Original Message -----
      > From: "Charles E. Campbell, Jr." <drchip@...>
      > To: "Oliver Fuchs" <oliverfuchs@...>
      > Cc: <vim@...>
      > Sent: Thursday, September 01, 2005 4:31 PM
      > Subject: Re: 1,5s/[^ ]*// or 1,5dw?
      >
      >
      > >Oliver Fuchs wrote:
      > >>I want to delete every first word of line1 up to line5...
      > >
      > >On Wed, 31 Aug 2005, Charles E. Campbell, Jr. wrote:
      > >>Also,
      > >>
      > >> :1,5s/\S\+//e
      > >
      > >>this means delete one or more non-whitespace characters until you get
      > >>to the next non-non-whitespace character. This is better because so
      > >>you can also delete leading whitespaces.
      > >
      > >To do that you'll need
      > >
      > > :1,5s/^\s*\S\+//e
      > >
      > >
      > >>But why you need to set e at
      > >>the end ([e] When the search pattern fails, do not issue an error
      > >>message)?
      > >
      > >How about a verbose explanation...
      > >
      > > 1,5 apply following ex command over lines 1 through 5
      > > s/ substitute
      > > ^ start from beginning of line
      > > \s match any white space
      > > * 0 to any amount of preceding atom (ie. 0 to any number of blanks)
      > > \S match any not-white-space
      > > \+ 1 to any amount of preceding atom (ie. 1+ of not-blanks)
      > > / substitute with the following text
      > > / end replacement text (in this case, that's no replacement)
      > > e don't complain/terminate/bloviate about non-matching problems
      > > (you'll get an error message if, without the "e", you try to apply
      > >this
      > > substitute to five blank lines at the start-of-file)
      > >
      > >
      > >>So thank you for your great help.
      > >
      > >You're welcome!
      > >Chip Campbell
      >
      > Why not just
      >
      > :1,5s/^\s*\S*//
      >
      > IIUC, that would
      > - delete the first Word on each line, with the whitespace before it (if
      > any)
      > - replace all-whitespace lines by empty lines (is that a problem?)
      > - but act only on the first 5 lines
      > - never complain (because there is always a match)
      >
      > add \s* after \S* to delete the first Word with the whitespace _around_ it

      Yes, there has to be a second \s like

      :1,5s/^\s*\S\+\s*//e (or :1,5s/^\s*\S*\s*//

      to match the whitespace behind the first deleted word.

      That brings me to my next question:
      :1,5s/\S*//e
      Why is now the leading whitespace not deleted.
      * means 0 or more and 0 of \S should be \s because \S is
      the opposite of \s? I think it means find more non-whitespace
      characters (1,2,3 ...) or find 0 of them. And a 0 non-whitespace
      character is a whitespace-character, isn't it? Or what else should a
      0 non-whitespace character be?
      0 \S = 1 \s, or not?

      Oliver

      >
      > NB. This works because the * multi is "greedy" (0 or more, as many as
      > possible)
      >
      >
      > Best regards,
      > Tony.
      >
      --
      ... don't touch the bang bang fruit
    • Tony Mechelynck
      ... From: Oliver Fuchs To: Sent: Friday, September 02, 2005 6:21 AM Subject: Re: 1,5s/[^ ]*// or 1,5dw? ... No, S*
      Message 2 of 18 , Sep 1, 2005
        ----- Original Message -----
        From: "Oliver Fuchs" <oliverfuchs@...>
        To: <vim@...>
        Sent: Friday, September 02, 2005 6:21 AM
        Subject: Re: 1,5s/[^ ]*// or 1,5dw?


        > On Thu, 01 Sep 2005, Tony Mechelynck wrote:
        >
        >> ----- Original Message -----
        >> From: "Charles E. Campbell, Jr." <drchip@...>
        >> To: "Oliver Fuchs" <oliverfuchs@...>
        >> Cc: <vim@...>
        >> Sent: Thursday, September 01, 2005 4:31 PM
        >> Subject: Re: 1,5s/[^ ]*// or 1,5dw?
        >>
        >>
        >> >Oliver Fuchs wrote:
        >> >>I want to delete every first word of line1 up to line5...
        >> >
        >> >On Wed, 31 Aug 2005, Charles E. Campbell, Jr. wrote:
        >> >>Also,
        >> >>
        >> >> :1,5s/\S\+//e
        >> >
        >> >>this means delete one or more non-whitespace characters until you get
        >> >>to the next non-non-whitespace character. This is better because so
        >> >>you can also delete leading whitespaces.
        >> >
        >> >To do that you'll need
        >> >
        >> > :1,5s/^\s*\S\+//e
        >> >
        >> >
        >> >>But why you need to set e at
        >> >>the end ([e] When the search pattern fails, do not issue an error
        >> >>message)?
        >> >
        >> >How about a verbose explanation...
        >> >
        >> > 1,5 apply following ex command over lines 1 through 5
        >> > s/ substitute
        >> > ^ start from beginning of line
        >> > \s match any white space
        >> > * 0 to any amount of preceding atom (ie. 0 to any number of blanks)
        >> > \S match any not-white-space
        >> > \+ 1 to any amount of preceding atom (ie. 1+ of not-blanks)
        >> > / substitute with the following text
        >> > / end replacement text (in this case, that's no replacement)
        >> > e don't complain/terminate/bloviate about non-matching problems
        >> > (you'll get an error message if, without the "e", you try to
        >> > apply
        >> >this
        >> > substitute to five blank lines at the start-of-file)
        >> >
        >> >
        >> >>So thank you for your great help.
        >> >
        >> >You're welcome!
        >> >Chip Campbell
        >>
        >> Why not just
        >>
        >> :1,5s/^\s*\S*//
        >>
        >> IIUC, that would
        >> - delete the first Word on each line, with the whitespace before it
        >> (if
        >> any)
        >> - replace all-whitespace lines by empty lines (is that a problem?)
        >> - but act only on the first 5 lines
        >> - never complain (because there is always a match)
        >>
        >> add \s* after \S* to delete the first Word with the whitespace _around_
        >> it
        >
        > Yes, there has to be a second \s like
        >
        > :1,5s/^\s*\S\+\s*//e (or :1,5s/^\s*\S*\s*//
        >
        > to match the whitespace behind the first deleted word.
        >
        > That brings me to my next question:
        > :1,5s/\S*//e
        > Why is now the leading whitespace not deleted.
        > * means 0 or more and 0 of \S should be \s because \S is
        > the opposite of \s? I think it means find more non-whitespace
        > characters (1,2,3 ...) or find 0 of them. And a 0 non-whitespace
        > character is a whitespace-character, isn't it? Or what else should a
        > 0 non-whitespace character be?
        > 0 \S = 1 \s, or not?

        No, \S* will match zero or more non-spaces, as many as possible, but will
        not match any spaces. If the whole search pattern is just \S*; it will match
        everywhere (matching the null string before any whitespace and matching as
        many nonspaces as possible when there are any). Then, since without /g at
        the end only one match per line is considered, whenever a line starts with a
        space, \S* will match zero nonspaces at start-of-line and replace "nothing"
        before the first space by "nothing", in effect never changing a line that
        starts with a space.

        OTOH, s/\S*//g will delete _all_ nonspaces from any lines in its range.

        Zero nonspaces is not one space, it is the null string (literally, "a string
        of length zero, not containing any spaces")


        Best regards,
        Tony.
      • Oliver Fuchs
        ... But what is a zero non-whitespace? That does not make sense because it does not exist? - so + is a better choice than * ... Ah, but that would not make
        Message 3 of 18 , Sep 2, 2005
          On Fri, 02 Sep 2005, Tony Mechelynck wrote:

          > ----- Original Message ----- From: "Oliver Fuchs"
          > <oliverfuchs@...> To: <vim@...> Sent: Friday,
          > September 02, 2005 6:21 AM Subject: Re: 1,5s/[^ ]*// or 1,5dw?
          >
          >
          > >On Thu, 01 Sep 2005, Tony Mechelynck wrote:
          > >
          > >>----- Original Message ----- From: "Charles E. Campbell, Jr."
          > >><drchip@...> To: "Oliver Fuchs"
          > >><oliverfuchs@...> Cc: <vim@...> Sent: Thursday,
          > >>September 01, 2005 4:31 PM Subject: Re: 1,5s/[^ ]*// or 1,5dw?
          > >>
          > >>
          > >>>Oliver Fuchs wrote:
          > >>>>I want to delete every first word of line1 up to line5...
          > >>>
          > >>>On Wed, 31 Aug 2005, Charles E. Campbell, Jr. wrote:
          > >>>>Also,
          > >>>>
          > >>>> :1,5s/\S\+//e
          > >>>
          > >>>>this means delete one or more non-whitespace characters until
          > >>>>you get to the next non-non-whitespace character. This is better
          > >>>>because so you can also delete leading whitespaces.
          > >>>
          > >>>To do that you'll need
          > >>>
          > >>> :1,5s/^\s*\S\+//e
          > >>>
          > >>>
          > >>>>But why you need to set e at the end ([e] When the search
          > >>>>pattern fails, do not issue an error message)?
          > >>>
          > >>>How about a verbose explanation...
          > >>>
          > >>> 1,5 apply following ex command over lines 1 through 5 s/
          > >>> substitute ^ start from beginning of line \s match any
          > >>> white space * 0 to any amount of preceding atom (ie. 0 to any
          > >>> number of blanks) \S match any not-white-space \+ 1 to any
          > >>> amount of preceding atom (ie. 1+ of not-blanks) / substitute
          > >>> with the following text / end replacement text (in this case,
          > >>> that's no replacement) e don't complain/terminate/bloviate
          > >>> about non-matching problems (you'll get an error message if,
          > >>> without the "e", you try to apply
          > >>>this substitute to five blank lines at the start-of-file)
          > >>>
          > >>>
          > >>>>So thank you for your great help.
          > >>>
          > >>>You're welcome! Chip Campbell
          > >>
          > >>Why not just
          > >>
          > >> :1,5s/^\s*\S*//
          > >>
          > >>IIUC, that would - delete the first Word on each line, with the
          > >>whitespace before it (if any) - replace all-whitespace lines by
          > >>empty lines (is that a problem?) - but act only on the first 5
          > >>lines - never complain (because there is always a match)
          > >>
          > >>add \s* after \S* to delete the first Word with the whitespace
          > >>_around_ it
          > >
          > >Yes, there has to be a second \s like
          > >
          > >:1,5s/^\s*\S\+\s*//e (or :1,5s/^\s*\S*\s*//
          > >
          > >to match the whitespace behind the first deleted word.
          > >
          > >That brings me to my next question: :1,5s/\S*//e Why is now the
          > >leading whitespace not deleted. * means 0 or more and 0 of \S
          > >should be \s because \S is the opposite of \s? I think it means
          > >find more non-whitespace characters (1,2,3 ...) or find 0 of them.
          > >And a 0 non-whitespace character is a whitespace-character, isn't
          > >it? Or what else should a 0 non-whitespace character be? 0 \S = 1
          > >\s, or not?
          >
          > No, \S* will match zero or more non-spaces, as many as possible, but
          > will not match any spaces.

          But what is a zero non-whitespace?
          That does not make sense because it does not exist? - so \+ is a better
          choice than *

          > If the whole search pattern is just \S*;
          > it will match everywhere (matching the null string before any
          > whitespace and matching as many nonspaces as possible when there are
          > any). Then, since without /g at the end only one match per line is
          > considered, whenever a line starts with a space, \S* will match zero
          > nonspaces at start-of-line and replace "nothing" before the first
          > space by "nothing", in effect never changing a line that starts with
          > a space.
          >
          > OTOH, s/\S*//g will delete _all_ nonspaces from any lines in its
          > range.
          >
          > Zero nonspaces is not one space, it is the null string (literally,
          > "a string of length zero, not containing any spaces")

          Ah, but that would not make any sense - or? If you have only this two
          possibilites: whitespace or non-whitespace, then a zero non-whitespace
          does not exist, or?

          Anyway, thanks for this terrific lesson in regular expressions.

          Oliver

          >
          > Best regards, Tony.
          >

          -- ... don't touch the bang bang fruit
        • Tony Mechelynck
          ... From: Oliver Fuchs To: Sent: Friday, September 02, 2005 10:35 PM Subject: Re: 1,5s/[^ ]*// or 1,5dw? ... It
          Message 4 of 18 , Sep 2, 2005
            ----- Original Message -----
            From: "Oliver Fuchs" <oliverfuchs@...>
            To: <vim@...>
            Sent: Friday, September 02, 2005 10:35 PM
            Subject: Re: 1,5s/[^ ]*// or 1,5dw?


            > On Fri, 02 Sep 2005, Tony Mechelynck wrote:
            >
            >> ----- Original Message ----- From: "Oliver Fuchs"
            >> <oliverfuchs@...> To: <vim@...> Sent: Friday,
            >> September 02, 2005 6:21 AM Subject: Re: 1,5s/[^ ]*// or 1,5dw?
            >>
            >>
            >> >On Thu, 01 Sep 2005, Tony Mechelynck wrote:
            >> >
            >> >>----- Original Message ----- From: "Charles E. Campbell, Jr."
            >> >><drchip@...> To: "Oliver Fuchs"
            >> >><oliverfuchs@...> Cc: <vim@...> Sent: Thursday,
            >> >>September 01, 2005 4:31 PM Subject: Re: 1,5s/[^ ]*// or 1,5dw?
            >> >>
            >> >>
            >> >>>Oliver Fuchs wrote:
            >> >>>>I want to delete every first word of line1 up to line5...
            >> >>>
            >> >>>On Wed, 31 Aug 2005, Charles E. Campbell, Jr. wrote:
            >> >>>>Also,
            >> >>>>
            >> >>>> :1,5s/\S\+//e
            >> >>>
            >> >>>>this means delete one or more non-whitespace characters until
            >> >>>>you get to the next non-non-whitespace character. This is better
            >> >>>>because so you can also delete leading whitespaces.
            >> >>>
            >> >>>To do that you'll need
            >> >>>
            >> >>> :1,5s/^\s*\S\+//e
            >> >>>
            >> >>>
            >> >>>>But why you need to set e at the end ([e] When the search
            >> >>>>pattern fails, do not issue an error message)?
            >> >>>
            >> >>>How about a verbose explanation...
            >> >>>
            >> >>> 1,5 apply following ex command over lines 1 through 5 s/
            >> >>> substitute ^ start from beginning of line \s match any
            >> >>> white space * 0 to any amount of preceding atom (ie. 0 to any
            >> >>> number of blanks) \S match any not-white-space \+ 1 to any
            >> >>> amount of preceding atom (ie. 1+ of not-blanks) / substitute
            >> >>> with the following text / end replacement text (in this case,
            >> >>> that's no replacement) e don't complain/terminate/bloviate
            >> >>> about non-matching problems (you'll get an error message if,
            >> >>> without the "e", you try to apply
            >> >>>this substitute to five blank lines at the start-of-file)
            >> >>>
            >> >>>
            >> >>>>So thank you for your great help.
            >> >>>
            >> >>>You're welcome! Chip Campbell
            >> >>
            >> >>Why not just
            >> >>
            >> >> :1,5s/^\s*\S*//
            >> >>
            >> >>IIUC, that would - delete the first Word on each line, with the
            >> >>whitespace before it (if any) - replace all-whitespace lines by
            >> >>empty lines (is that a problem?) - but act only on the first 5
            >> >>lines - never complain (because there is always a match)
            >> >>
            >> >>add \s* after \S* to delete the first Word with the whitespace
            >> >>_around_ it
            >> >
            >> >Yes, there has to be a second \s like
            >> >
            >> >:1,5s/^\s*\S\+\s*//e (or :1,5s/^\s*\S*\s*//
            >> >
            >> >to match the whitespace behind the first deleted word.
            >> >
            >> >That brings me to my next question: :1,5s/\S*//e Why is now the
            >> >leading whitespace not deleted. * means 0 or more and 0 of \S
            >> >should be \s because \S is the opposite of \s? I think it means
            >> >find more non-whitespace characters (1,2,3 ...) or find 0 of them.
            >> >And a 0 non-whitespace character is a whitespace-character, isn't
            >> >it? Or what else should a 0 non-whitespace character be? 0 \S = 1
            >> >\s, or not?
            >>
            >> No, \S* will match zero or more non-spaces, as many as possible, but
            >> will not match any spaces.
            >
            > But what is a zero non-whitespace?
            > That does not make sense because it does not exist? - so \+ is a better
            > choice than *
            >
            >> If the whole search pattern is just \S*;
            >> it will match everywhere (matching the null string before any
            >> whitespace and matching as many nonspaces as possible when there are
            >> any). Then, since without /g at the end only one match per line is
            >> considered, whenever a line starts with a space, \S* will match zero
            >> nonspaces at start-of-line and replace "nothing" before the first
            >> space by "nothing", in effect never changing a line that starts with
            >> a space.
            >>
            >> OTOH, s/\S*//g will delete _all_ nonspaces from any lines in its
            >> range.
            >>
            >> Zero nonspaces is not one space, it is the null string (literally,
            >> "a string of length zero, not containing any spaces")
            >
            > Ah, but that would not make any sense - or? If you have only this two
            > possibilites: whitespace or non-whitespace, then a zero non-whitespace
            > does not exist, or?

            It makes sense, since zero non-whitespaces can be part of a pattern, as in
            the earlier example:

            s/^\s*\S*\s*//

            will match a sequence consisting of

            begin-of-line
            zero or more whitespace characters, as many as possible (but no
            non-whitespaces)
            zero or more non-whitespaces, as many as possible (but no whitespace)
            zero or more whitespaces, as many as possible (but no non-whitespaces)

            and replace it all by nothing.

            The result is that the first Word on a line and its surrounding space are
            deleted, *regardless* of whether there is whitespace before it (or after it:
            a line with only one Word gets replaced by an empty line).

            A line consisting only of whitespace also gets replaced by an empty line,
            since n spaces are seen as "n spaces" + "zero nonspaces" + "zero spaces".

            An empty line is replaced (by an empty line) (the pattern matches zero
            spaces + zero nonspaces + zero spaces), meaning that if all lines in the
            range are empty, there is no error message.

            To go back to your reasoning: I can have whitespace, or non-whitespace, or
            nothing: it _is_ possible to match the empty string. Zero non-whitespace is
            not "absurd" or "impossible", it is an instance of the empty string.

            >
            > Anyway, thanks for this terrific lesson in regular expressions.
            >
            > Oliver

            My pleasure.
            >
            >>
            >> Best regards, Tony.

            I wouldn't have believed that some people would have it so hard to grasp
            that "zero X" does not mean "one non-X". 100 apples is not the same as
            "hundred apples and eleven pears", is it? (the former is 1 hundred apples +
            0 ten apples + 0 unit apples; the latter would be 1 hundred apples plus 1
            ten non-apples plus 1 unit non-apples). If you do *not* understand what I'm
            saying, then maybe (just maybe) a revision of first-grade arithmetic would
            be in order.

            Best regards,
            Tony.
          • Oliver Fuchs
            ... Yes - it makes sense as long as you are using a substituion - what about: g/ S*/d Not even vim can handle this correctly (it ends up with no lines in
            Message 5 of 18 , Sep 3, 2005
              On Sat, 03 Sep 2005, Tony Mechelynck wrote:

              > ----- Original Message ----- From: "Oliver Fuchs"
              > <oliverfuchs@...> To: <vim@...> Sent: Friday,
              > September 02, 2005 10:35 PM Subject: Re: 1,5s/[^ ]*// or 1,5dw?
              >
              >
              > >On Fri, 02 Sep 2005, Tony Mechelynck wrote:
              > >
              > >>----- Original Message ----- From: "Oliver Fuchs"
              > >><oliverfuchs@...> To: <vim@...> Sent: Friday,
              > >>September 02, 2005 6:21 AM Subject: Re: 1,5s/[^ ]*// or 1,5dw?
              > >>
              > >>
              > >>>On Thu, 01 Sep 2005, Tony Mechelynck wrote:
              > >>>
              > >>>>----- Original Message ----- From: "Charles E. Campbell, Jr."
              > >>>><drchip@...> To: "Oliver Fuchs"
              > >>>><oliverfuchs@...> Cc: <vim@...> Sent: Thursday,
              > >>>>September 01, 2005 4:31 PM Subject: Re: 1,5s/[^ ]*// or 1,5dw?
              > >>>>
              > >>>>
              > >>>>>Oliver Fuchs wrote:
              > >>>>>>I want to delete every first word of line1 up to line5...
              > >>>>>
              > >>>>>On Wed, 31 Aug 2005, Charles E. Campbell, Jr. wrote:
              > >>>>>>Also,
              > >>>>>>
              > >>>>>> :1,5s/\S\+//e
              > >>>>>
              > >>>>>>this means delete one or more non-whitespace characters until
              > >>>>>>you get to the next non-non-whitespace character. This is
              > >>>>>>better because so you can also delete leading whitespaces.
              > >>>>>
              > >>>>>To do that you'll need
              > >>>>>
              > >>>>> :1,5s/^\s*\S\+//e
              > >>>>>
              > >>>>>
              > >>>>>>But why you need to set e at the end ([e] When the search
              > >>>>>>pattern fails, do not issue an error message)?
              > >>>>>
              > >>>>>How about a verbose explanation...
              > >>>>>
              > >>>>> 1,5 apply following ex command over lines 1 through 5 s/
              > >>>>> substitute ^ start from beginning of line \s match any
              > >>>>> white space * 0 to any amount of preceding atom (ie. 0 to
              > >>>>> any number of blanks) \S match any not-white-space \+ 1 to
              > >>>>> any amount of preceding atom (ie. 1+ of not-blanks) /
              > >>>>> substitute with the following text / end replacement text
              > >>>>> (in this case, that's no replacement) e don't
              > >>>>> complain/terminate/bloviate about non-matching problems
              > >>>>> (you'll get an error message if, without the "e", you try to
              > >>>>> apply
              > >>>>>this substitute to five blank lines at the start-of-file)
              > >>>>>
              > >>>>>
              > >>>>>>So thank you for your great help.
              > >>>>>
              > >>>>>You're welcome! Chip Campbell
              > >>>>
              > >>>>Why not just
              > >>>>
              > >>>> :1,5s/^\s*\S*//
              > >>>>
              > >>>>IIUC, that would - delete the first Word on each line, with the
              > >>>>whitespace before it (if any) - replace all-whitespace lines by
              > >>>>empty lines (is that a problem?) - but act only on the first 5
              > >>>>lines - never complain (because there is always a match)
              > >>>>
              > >>>>add \s* after \S* to delete the first Word with the whitespace
              > >>>>_around_ it
              > >>>
              > >>>Yes, there has to be a second \s like
              > >>>
              > >>>:1,5s/^\s*\S\+\s*//e (or :1,5s/^\s*\S*\s*//
              > >>>
              > >>>to match the whitespace behind the first deleted word.
              > >>>
              > >>>That brings me to my next question: :1,5s/\S*//e Why is now the
              > >>>leading whitespace not deleted. * means 0 or more and 0 of \S
              > >>>should be \s because \S is the opposite of \s? I think it means
              > >>>find more non-whitespace characters (1,2,3 ...) or find 0 of
              > >>>them. And a 0 non-whitespace character is a
              > >>>whitespace-character, isn't it? Or what else should a 0
              > >>>non-whitespace character be? 0 \S = 1 \s, or not?
              > >>
              > >>No, \S* will match zero or more non-spaces, as many as possible,
              > >>but will not match any spaces.
              > >
              > >But what is a zero non-whitespace? That does not make sense
              > >because it does not exist? - so \+ is a better choice than *
              > >
              > >>If the whole search pattern is just \S*; it will match everywhere
              > >>(matching the null string before any whitespace and matching as
              > >>many nonspaces as possible when there are any). Then, since
              > >>without /g at the end only one match per line is considered,
              > >>whenever a line starts with a space, \S* will match zero nonspaces
              > >>at start-of-line and replace "nothing" before the first space by
              > >>"nothing", in effect never changing a line that starts with a
              > >>space.
              > >>
              > >>OTOH, s/\S*//g will delete _all_ nonspaces from any lines in its
              > >>range.
              > >>
              > >>Zero nonspaces is not one space, it is the null string (literally,
              > >>"a string of length zero, not containing any spaces")
              > >
              > >Ah, but that would not make any sense - or? If you have only this
              > >two possibilites: whitespace or non-whitespace, then a zero
              > >non-whitespace does not exist, or?
              >
              > It makes sense, since zero non-whitespaces can be part of a pattern,
              > as in the earlier example:
              >
              > s/^\s*\S*\s*//
              >
              > will match a sequence consisting of
              >
              > begin-of-line zero or more whitespace characters, as many as
              > possible (but no non-whitespaces) zero or more non-whitespaces,
              > as many as possible (but no whitespace) zero or more whitespaces,
              > as many as possible (but no non-whitespaces)
              >
              > and replace it all by nothing.

              Yes - it makes sense as long as you are using a substituion - what
              about:

              g/\S*/d

              Not even vim can handle this correctly (it ends up with "no lines in
              buffer" but there is still line 1).

              > The result is that the first Word on a line and its surrounding
              > space are deleted, *regardless* of whether there is whitespace
              > before it (or after it: a line with only one Word gets replaced by
              > an empty line).
              >
              > A line consisting only of whitespace also gets replaced by an empty
              > line, since n spaces are seen as "n spaces" + "zero nonspaces" +
              > "zero spaces".
              >
              > An empty line is replaced (by an empty line) (the pattern matches
              > zero spaces + zero nonspaces + zero spaces), meaning that if all
              > lines in the range are empty, there is no error message.
              >
              > To go back to your reasoning: I can have whitespace, or
              > non-whitespace, or nothing:

              a) Yes, you use the term of nothing - so \S is the opposite of \s
              and \s is a whitespace character - so \S is everything else that is
              not a whitespace - that means also the nothing - or am I wrong here.
              b) The h: \S says that \S is a "Ordinary atom" and here a "Character
              class" with "The ones below only match ASCII characters, as indicated
              by the range". So nothing is not a ASCII character - or am I wrong
              here?
              If nothing is in the non-whitespace class of \S than a zero nonspace
              does not makes sense.
              If it is true that \S and \s are classes that only matches ASCII
              characters and nothing is not a ASCII character then a zero nonspace
              does not makes sense.

              From here on I thought that using a zero nonspace does not make sense
              you see?

              > it _is_ possible to match the empty
              > string. Zero non-whitespace is not "absurd" or "impossible", it is
              > an instance of the empty string.

              Why can't I then use

              g/\S\{0\}/d

              to delete the empty lines?

              >
              > >
              > >Anyway, thanks for this terrific lesson in regular expressions.
              > >
              > >Oliver
              >
              > My pleasure.
              > >
              > >>
              > >>Best regards, Tony.
              >
              > I wouldn't have believed that some people would have it so hard to
              > grasp that "zero X" does not mean "one non-X". 100 apples is not the
              > same as "hundred apples and eleven pears", is it? (the former is 1
              > hundred apples + 0 ten apples + 0 unit apples; the latter would be 1
              > hundred apples plus 1 ten non-apples plus 1 unit non-apples). If you
              > do *not* understand what I'm saying, then maybe (just maybe) a
              > revision of first-grade arithmetic would be in order.

              How did you guess that I am at elementary school? I understand what
              you are saying but I was only arguing from the vim help - that was not
              quite clear to me.
              I hope it wasn't boring for you.

              Oliver
              --
              ... don't touch the bang bang fruit
            • Bill McCarthy
              ... Vim needs to put the cursor somewhere. After your global ... -- Best regards, Bill
              Message 6 of 18 , Sep 3, 2005
                On Sat 3-Sep-05 3:27pm -0500, Oliver Fuchs wrote:

                > Yes - it makes sense as long as you are using a substituion - what
                > about:
                >
                > g/\S*/d
                >
                > Not even vim can handle this correctly (it ends up with "no lines in
                > buffer" but there is still line 1).

                Vim needs to put the cursor somewhere. After your global
                command, try:

                :saveas foo
                :!dir foo ( or :!ls -l foo )

                --
                Best regards,
                Bill
              • Tony Mechelynck
                ... From: Oliver Fuchs To: Tony Mechelynck Sent: Saturday, September 03, 2005 10:24 PM Subject:
                Message 7 of 18 , Sep 4, 2005
                  ----- Original Message -----
                  From: "Oliver Fuchs" <oliverfuchs@...>
                  To: "Tony Mechelynck" <antoine.mechelynck@...>
                  Sent: Saturday, September 03, 2005 10:24 PM
                  Subject: Re: 1,5s/[^ ]*// or 1,5dw?
                  [...]
                  > Why can't I then use
                  >
                  > g/\S\{0\}/d
                  >
                  > to delete the empty lines?
                  [...]

                  To delete the empty lines (and keep the nonempty lines), use something that
                  will match _only_ empty lines, for instance

                  g/^$/d

                  (matching lines where begin-of-line is immediately followed by end-of-line).
                  \S\{0\} is not a well-formed pattern AFAICT
                  \S\{} or \S\{0} will match the empty string "at any position in a line", so
                  g/\S{}/d would delete everything (the empty string is a substring of every
                  line).

                  Note: Except when straying off-topic, please reply to the list, not by
                  private mail, so if I err or cannot answer, other people have an occasion to
                  see it.


                  Best regards,
                  Tony.
                Your message has been successfully submitted and would be delivered to recipients shortly.