[comp.editors] changing a ! to a \nC where \n is a newline

martin@mwtech.UUCP (Martin Weitzel) (09/22/90)

In article <1990Sep20.213216.19049@ddsw1.MCS.COM> dattier@ddsw1.MCS.COM (David W. Tamkin) writes:
>coleman@cam.nist.gov (Sean Sheridan Coleman) said in <5015@alpha.cam.nist.gov>:
[...]
>| How about the reverse, replace a newline with a character?
>
>I can't think of a global way to do that, [...]

Easy enough: The "g"lobal command will handle most cases, though it's
sometimes required to make the lines that should be appended to others
unique before appending, so that the extra blank the j-command introduces
can be eliminated. If the lines to be appended start all with a C in
column one, you could
	1)	:%s/^C/some-unique-string/
	2)	:g/^some-unique-string/-,.j
	3)	:%s/ some-unique-string//

An other possibility were to do this with shell tools, eg.
	awk '
		BEGIN { ORS = "" }
		NR==1 { print; next }
		/^C/ { print substr($0, 2); next }
		{ print "\n" $0 }
		END { print "\n" }
	'
As you can pipe each part of the text you edit through an external command
you can easily extend the features of vi to everything that can be done
with shell tools.
-- 
Martin Weitzel, email: martin@mwtech.UUCP, voice: 49-(0)6151-6 56 83