vim | replacement question

2006-09-20 Thread Nikolaos A. Patsopoulos

Hi all!

Another replacement question:

how can I replace all occurrence of a pattern except a given one, e.g. 
the first or third?


the code for all occurrences I use is:

:%s/a.\{-}//g

Thanks in advance,

Nikos



Re: vim | replacement question

2006-09-20 Thread Nikolaos A. Patsopoulos

Yakov Lerner wrote:

On 9/20/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote:

Hi all!

Another replacement question:

how can I replace all occurrence of a pattern except a given one, e.g.
the first or third?

the code for all occurrences I use is:

:%s/a.\{-}//g


/pattern/+1,$s///g

Yakov



Thanks!
Nikos



Re: vim | replacement question

2006-09-20 Thread Charles E Campbell Jr

Nikolaos A. Patsopoulos wrote:


Another replacement question:

how can I replace all occurrence of a pattern except a given one, e.g. 
the first or third?


the code for all occurrences I use is:

:%s/a.\{-}//g

Thanks in advance,


I see that others have given the answer to the specific question you 
asked, so I won't repeat that.

However, a related capability is to use the c flag (for confirm):

 :%s/a.\{-}//gc

Regards,
Chip Campbell



Re: vim | replacement question

2006-09-15 Thread Nikolaos A. Patsopoulos

A.J.Mechelynck wrote:

Nikolaos A. Patsopoulos wrote:

A.J.Mechelynck wrote:

Nikolaos A. Patsopoulos wrote:

Hi,
another two questions:
1. I want to delete all text that has a specific pattern. I use the 
following code with s command but I want to keep the \a character 
in the beginning:


:%s/\a,\_.\{-}\/td\/tr/


To delete everything that matches a certain pattern

:%s/pattern//g

(i.e., replace by nothing). To keep something at the start, see

:help /\zs
:help /\@=



2.
how can I join lines that have non-numerical characters?

e.g.
153
Purdue
Canc Ct
1256

should be
153
Purdue Canc Ct
1256

Thanks in advance,

Nikos




(untested)

:%g/\D.*\n.*\D/join

i.e. join two successive lines, adding an intervening space, if 
there is at least one non-digit anywhere in each of them.



Best regards,
Tony.


For 1 I came up with this:

:%s/\(\a\),\_.\{-}\/td\/tr/\1

about 2

:%g/\D.*\n.*\D/join

.* captures some numeric values in between. Maybe sth like this would 
be better:


:%g/\D.*\n.*[^\d]\D/join

but this is not right.



Well, it all depends on what you want to do. If there are both digits 
and nondigits on a single line, do you want to join it or not? Or does 
it depend on whether the nondigits are or aren't whitespace?


I would suggest that you read the helpfile :help pattern.txt and 
especially the part starting at :help pattern-overview and extending 
over 150 lines or more.



Best regards,



Well that worked for me fine:

:%g/\D\n\D/join

You are right. Everything depends on what you want to do.

Another small question:

If you want to an empty line to the end of a file what does the trick?

I tried :,$s/\(.*\)/\1\n

but doesn't work

Thanks,

Nikos



Re: vim | replacement question

2006-09-15 Thread A.J.Mechelynck

Nikolaos A. Patsopoulos wrote:

A.J.Mechelynck wrote:

Nikolaos A. Patsopoulos wrote:

A.J.Mechelynck wrote:

Nikolaos A. Patsopoulos wrote:

Hi,
another two questions:
1. I want to delete all text that has a specific pattern. I use the 
following code with s command but I want to keep the \a character 
in the beginning:


:%s/\a,\_.\{-}\/td\/tr/


To delete everything that matches a certain pattern

:%s/pattern//g

(i.e., replace by nothing). To keep something at the start, see

:help /\zs
:help /\@=



2.
how can I join lines that have non-numerical characters?

e.g.
153
Purdue
Canc Ct
1256

should be
153
Purdue Canc Ct
1256

Thanks in advance,

Nikos




(untested)

:%g/\D.*\n.*\D/join

i.e. join two successive lines, adding an intervening space, if 
there is at least one non-digit anywhere in each of them.



Best regards,
Tony.


For 1 I came up with this:

:%s/\(\a\),\_.\{-}\/td\/tr/\1

about 2

:%g/\D.*\n.*\D/join

.* captures some numeric values in between. Maybe sth like this would 
be better:


:%g/\D.*\n.*[^\d]\D/join

but this is not right.



Well, it all depends on what you want to do. If there are both digits 
and nondigits on a single line, do you want to join it or not? Or does 
it depend on whether the nondigits are or aren't whitespace?


I would suggest that you read the helpfile :help pattern.txt and 
especially the part starting at :help pattern-overview and extending 
over 150 lines or more.



Best regards,



Well that worked for me fine:

:%g/\D\n\D/join

You are right. Everything depends on what you want to do.

Another small question:

If you want to an empty line to the end of a file what does the trick?

I tried :,$s/\(.*\)/\1\n

but doesn't work

Thanks,

Nikos




To add an empty line at the end of the file

GoEsc

or in a script

normal Go^[

where ^[ is hit Ctrl-V hit Esc (replace Ctrl-V by Ctrl-Q if you use 
Ctrl-V to paste the clipboard)


To remove an empty line at the end of the file

:if getline($) =~ '^\s*$' | $d | endif

(if the last line is all whitespace, remove it)

To remove any number of empty lines at the end:

:while getline($) =~ '^\s*$' | $d | endwhile


Best regards,
Tony.


Re: vim | replacement question

2006-09-15 Thread Tim Chase

To add an empty line at the end of the file

GoEsc

or in a script

normal Go^[

where ^[ is hit Ctrl-V hit Esc (replace Ctrl-V by Ctrl-Q if you use 
Ctrl-V to paste the clipboard)


Additionally, in a script, you can use

:$put =''

to add empty lines at the bottom of the file


To remove an empty line at the end of the file

:if getline($) =~ '^\s*$' | $d | endif

(if the last line is all whitespace, remove it)


or alternatively:

:/^\s*\%$/d


To remove any number of empty lines at the end:

:while getline($) =~ '^\s*$' | $d | endwhile


or alternatively

:%s/\_s*\%$

will remove all the trailing whitespace in the file.  If you want 
to only remove truely blank lines (no whitespace in them) you can use


:%s/\n*\%$/

So many ways to do the same thing.  Strange that I like that 
ability in Vim, but abhor perl for the same reason. :) (maybe 
because I write vim one-liners as a use-once-and-dispose-of-it, 
and would grow to hate such opaque hacks if I had to go back and 
read them later, like one would have to do with perl code)


-tim








vim | replacement question

2006-09-14 Thread Nikolaos A. Patsopoulos

Hi,
another two questions:
1. I want to delete all text that has a specific pattern. I use the 
following code with s command but I want to keep the \a character in the 
beginning:


:%s/\a,\_.\{-}\/td\/tr/

2.
how can I join lines that have non-numerical characters?

e.g.
153
Purdue
Canc Ct
1256

should be
153
Purdue Canc Ct
1256

Thanks in advance,

Nikos



Re: vim | replacement question

2006-09-14 Thread A.J.Mechelynck

Nikolaos A. Patsopoulos wrote:

Hi,
another two questions:
1. I want to delete all text that has a specific pattern. I use the 
following code with s command but I want to keep the \a character in the 
beginning:


:%s/\a,\_.\{-}\/td\/tr/


To delete everything that matches a certain pattern

:%s/pattern//g

(i.e., replace by nothing). To keep something at the start, see

:help /\zs
:help /\@=



2.
how can I join lines that have non-numerical characters?

e.g.
153
Purdue
Canc Ct
1256

should be
153
Purdue Canc Ct
1256

Thanks in advance,

Nikos




(untested)

:%g/\D.*\n.*\D/join

i.e. join two successive lines, adding an intervening space, if there is 
at least one non-digit anywhere in each of them.



Best regards,
Tony.


Re: vim | replacement question

2006-09-14 Thread Nikolaos A. Patsopoulos

A.J.Mechelynck wrote:

Nikolaos A. Patsopoulos wrote:

Hi,
another two questions:
1. I want to delete all text that has a specific pattern. I use the 
following code with s command but I want to keep the \a character in 
the beginning:


:%s/\a,\_.\{-}\/td\/tr/


To delete everything that matches a certain pattern

:%s/pattern//g

(i.e., replace by nothing). To keep something at the start, see

:help /\zs
:help /\@=



2.
how can I join lines that have non-numerical characters?

e.g.
153
Purdue
Canc Ct
1256

should be
153
Purdue Canc Ct
1256

Thanks in advance,

Nikos




(untested)

:%g/\D.*\n.*\D/join

i.e. join two successive lines, adding an intervening space, if there 
is at least one non-digit anywhere in each of them.



Best regards,
Tony.


For 1 I came up with this:

:%s/\(\a\),\_.\{-}\/td\/tr/\1

about 2

:%g/\D.*\n.*\D/join

.* captures some numeric values in between. Maybe sth like this would be 
better:


:%g/\D.*\n.*[^\d]\D/join

but this is not right.

--
Nikolaos A. Patsopoulos, MD
Department of Hygiene and Epidemiology
University of Ioannina School of Medicine
University Campus
Ioannina 45110
Greece
Tel: (+30) 26510-97804
mobile: +30 6972882016
Fax: (+30) 26510-97867 (care of Nikolaos A. Patsopoulos)
e-mail: [EMAIL PROTECTED]