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

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Oliver Fuchs
Hi all,

I want to delete every first word of line1 up to line5. I could do this
with:

1,5s/[^ ]*//

Is there also a possibility to use the dw command for lines 1-5 with
something like

1,5dw

Oliver
--
... don't touch the bang bang fruit
Reply | Threaded
Open this post in threaded view
|

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

Charles E Campbell Jr
Oliver Fuchs wrote:

>I want to delete every first word of line1 up to line5. I could do this
>with:
>
>1,5s/[^ ]*//
>  
>

Also,

  :1,5s/\S\+//e

>Is there also a possibility to use the dw command for lines 1-5 with
>something like
>
>1,5dw
>
>  
>

dw is not an ex-mode command, its a normal mode command.  So, to mix the
two, try

:1,5norm! dw

Regards,
Chip Campbell


Reply | Threaded
Open this post in threaded view
|

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

Mikołaj Machowski
Dnia ?roda, 31 sierpnia 2005 22:50, Charles E. Campbell, Jr. napisa?:
>
> dw is not an ex-mode command, its a normal mode command.  So, to mix the
> two, try
>
> :1,5norm! dw
>

Note that this will fail with blank characters as first characters in
line, better::

    :1,5norm! ^dw

s/// solution with \S or [^ ] is also better because of punctuation
characters. Maybe::

    :1,5norm! ^dW

could fix that.

m.

Reply | Threaded
Open this post in threaded view
|

ctags conflict with xemacs

Tim Johnson-3
NOTE: Have two partitions/ RH 9.0 on one and
Slack 10.0 (under construction) on other.

I've just installed Xemacs on the slack partition,
'make install' copies the ctags and etags binaries bundled
with Xemacs to /usr/local/bin.

Now when I start vim, it complains that ctags is incompatible.
There are 'ctags' & 'etags' binaries at /usr/bin. How can I
resolve this conflict so that I can have both of these valuable
editors working with compatible tags binaries?

Example: are the binaries at /usr/bin usable and how to change
path settings?

I have done any configuration with vim in a long time, but
as far as I know, ctags is being run from ~/.vim/plugins/TagsMenu.vim.

TIA
Tim
--
Tim Johnson <[hidden email]>
      http://www.alaska-internet-solutions.com
Reply | Threaded
Open this post in threaded view
|

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

Oliver Fuchs
In reply to this post by Charles E Campbell Jr
On Wed, 31 Aug 2005, Charles E. Campbell, Jr. wrote:

> Oliver Fuchs wrote:
>
> >I want to delete every first word of line1 up to line5. I could do this
> >with:
> >
> >1,5s/[^ ]*//
> >
> >
>
> Also,
>
>  :1,5s/\S\+//e

Hi,
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. But why  you need to set e at
the end ([e] When the search pattern fails, do not issue an error
message)?

> >Is there also a possibility to use the dw command for lines 1-5 with
> >something like
> >
> >1,5dw
> >
> dw is not an ex-mode command, its a normal mode command.  So, to mix the two, try
> :1,5norm! dw

So h: norm gives me this:
"Execute Normal mode commands {commands} for each line in the
{range}."
But to be honest I never  would have thought that this is the way to
combine ex-mode and normal-mode  commands

>
> Regards,
> Chip Campbell

So thank you for your great help.

Oliver
--
... don't touch the bang bang fruit
Reply | Threaded
Open this post in threaded view
|

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

Oliver Fuchs
In reply to this post by Mikołaj Machowski
On Thu, 01 Sep 2005, Mikolaj Machowski wrote:

> Dnia ?roda, 31 sierpnia 2005 22:50, Charles E. Campbell, Jr. napisa?:
> >
> > dw is not an ex-mode command, its a normal mode command.  So, to mix the
> > two, try
> >
> > :1,5norm! dw
> >
>
> Note that this will fail with blank characters as first characters in
> line, better::
>
>     :1,5norm! ^dw
>
> s/// solution with \S or [^ ] is also better because of punctuation
> characters. Maybe::
>
>     :1,5norm! ^dW
>
> could fix that.

Ah, that means go to the first non blank character and delete
a "WORD" (a sequence of non-blank characters).

Great - thank you for your help.

Oliver

> m.

--
... don't touch the bang bang fruit
Reply | Threaded
Open this post in threaded view
|

Re: ctags conflict with xemacs

Chris Allen
In reply to this post by Tim Johnson-3
On 31/08/05, Tim Johnson <[hidden email]> wrote:
> Now when I start vim, it complains that ctags is incompatible.
> There are 'ctags' & 'etags' binaries at /usr/bin. How can I
> resolve this conflict so that I can have both of these valuable
> editors working with compatible tags binaries?

You can make Vim's taglist plugin happy by setting Tlist_Ctags_Cmd to
your proper exuberant ctags binary with something like:

    let Tlist_Ctags_Cmd="/usr/bin/ctags"

in your .vimrc
 
> Example: are the binaries at /usr/bin usable and how to change
> path settings?

Generally you probably want your /usr/local/bin ahead of /usr/bin in
your path.  That allows programs you've installed locally to over-ride
your standard ones, as they are doing in this case.
Of course, it is highly unlikely that you really want to replace your
nice exuberant ctags installation with the one Emacs includes (which
is probably very brain dead).  I would guess that you can safely
remove the ctags it (very impolitely) installed in /usr/local/bin.

You might not have exuberant ctags.  If you do, however, it should
also have its own etags clone which is better, anyway.  If that is the
case then you should be able to quite happily delete both of them and
use the exuberant ctags stuff.

HTH,
Chris Allen
Reply | Threaded
Open this post in threaded view
|

Re: ctags conflict with xemacs

Chris Allen
In reply to this post by Tim Johnson-3
On 31/08/05, Tim Johnson <[hidden email]> wrote:
> I have done any configuration with vim in a long time, but
> as far as I know, ctags is being run from ~/.vim/plugins/TagsMenu.vim.

Apologies, you did say TagsMenu, and I went off thinking taglist.  The
variable you want is TagsMenu_ctagsCommand, not the variable in the
let statement I gave you previously.

Sorry,
Chris Allen
Reply | Threaded
Open this post in threaded view
|

Re: ctags conflict with xemacs

Tim Johnson-3
* Chris Allen <[hidden email]> [050831 21:20]:
> On 31/08/05, Tim Johnson <[hidden email]> wrote:
> > I have done any configuration with vim in a long time, but
> > as far as I know, ctags is being run from ~/.vim/plugins/TagsMenu.vim.
>
> Apologies, you did say TagsMenu, and I went off thinking taglist.  The
> variable you want is TagsMenu_ctagsCommand, not the variable in the
> let statement I gave you previously.
 
  Thanks Chris. That make it all clear.
  Cheers
  tim

> Sorry,
> Chris Allen

--
Tim Johnson <[hidden email]>
      http://www.alaska-internet-solutions.com
Reply | Threaded
Open this post in threaded view
|

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

Charles E Campbell Jr
In reply to this post by Oliver Fuchs
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

Reply | Threaded
Open this post in threaded view
|

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

A.J.Mechelynck
----- Original Message -----
From: "Charles E. Campbell, Jr." <[hidden email]>
To: "Oliver Fuchs" <[hidden email]>
Cc: <[hidden email]>
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

NB. This works because the * multi is "greedy" (0 or more, as many as
possible)


Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

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

Oliver Fuchs
On Thu, 01 Sep 2005, Tony Mechelynck wrote:

> ----- Original Message -----
> From: "Charles E. Campbell, Jr." <[hidden email]>
> To: "Oliver Fuchs" <[hidden email]>
> Cc: <[hidden email]>
> 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
Reply | Threaded
Open this post in threaded view
|

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

A.J.Mechelynck
----- Original Message -----
From: "Oliver Fuchs" <[hidden email]>
To: <[hidden email]>
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." <[hidden email]>
>> To: "Oliver Fuchs" <[hidden email]>
>> Cc: <[hidden email]>
>> 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.


Reply | Threaded
Open this post in threaded view
|

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

Oliver Fuchs
On Fri, 02 Sep 2005, Tony Mechelynck wrote:

> ----- Original Message ----- From: "Oliver Fuchs"
> <[hidden email]> To: <[hidden email]> 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."
> >><[hidden email]> To: "Oliver Fuchs"
> >><[hidden email]> Cc: <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

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

A.J.Mechelynck
----- Original Message -----
From: "Oliver Fuchs" <[hidden email]>
To: <[hidden email]>
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"
>> <[hidden email]> To: <[hidden email]> 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."
>> >><[hidden email]> To: "Oliver Fuchs"
>> >><[hidden email]> Cc: <[hidden email]> 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.


Reply | Threaded
Open this post in threaded view
|

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

Oliver Fuchs
On Sat, 03 Sep 2005, Tony Mechelynck wrote:

> ----- Original Message ----- From: "Oliver Fuchs"
> <[hidden email]> To: <[hidden email]> 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"
> >><[hidden email]> To: <[hidden email]> 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."
> >>>><[hidden email]> To: "Oliver Fuchs"
> >>>><[hidden email]> Cc: <[hidden email]> 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

Reply | Threaded
Open this post in threaded view
|

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

Bill McCarthy
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


Reply | Threaded
Open this post in threaded view
|

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

A.J.Mechelynck
In reply to this post by A.J.Mechelynck
----- Original Message -----
From: "Oliver Fuchs" <[hidden email]>
To: "Tony Mechelynck" <[hidden email]>
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.