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
Go<Esc>
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.