Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!esosun!cogen!alen From: alen@cogen.UUCP (Alen Shapiro) Newsgroups: comp.unix.questions Subject: Re: Invisible Ascii with VI Message-ID: <371@cogen.UUCP> Date: Tue, 6-Oct-87 14:57:10 EDT Article-I.D.: cogen.371 Posted: Tue Oct 6 14:57:10 1987 Date-Received: Fri, 9-Oct-87 06:42:45 EDT References: <258@unx1.UUCP> <469@devon.UUCP> <8807@mimsy.UUCP> <250@hobbes.UUCP> <1805@ncr-sd.SanDiego.NCR.COM> Reply-To: alen@cogen.UUCP (Alen Shapiro) Organization: Cogensys, LaJolla, Calf. Lines: 42 Keywords: hack miracle - the impossible takes a little longer Summary: how to cheat and win at vi In article <1805@ncr-sd.SanDiego.NCR.COM> geoff@ncr-sd.SanDiego.NCR.COM (Geoffrey R. Walton) writes: >In article <250@hobbes.UUCP> root@hobbes.UUCP (John Plocher) writes: >>+---- chris@mimsy.UUCP (Chris Torek) writes in <8807@mimsy.UUCP> ---- >><< a problem with removing trailing ^M's from lines in vi >> >>| : % s / ^V ^M $ / / >>| works fine for me. >>| (Going the *other* way---adding ^Ms---is another matter entirely.) >What's wrong with: >:g/$/s// >This, of course, supposes that you want to insert a blank line >between each line of existing text. (That isn't what you want >to do? OK, I give up. Why _DO_ you want to add "hard" carriage >returns to the lines in your file?) if you REALLY want to do this in vi - try this (it works on the sun) and has the added advantage of not adding ^Ms to lines already ending in one. vi your favourite file - (/etc/termcap will do) do the following; /[^ ^V ^M $]/ # no spaces in the real thing though A ^V ^M # again no spaces - this should add a ^M to a line " m y # put the ^M int reg 'M' (one real space on this line) :map v n"mpV # def macro v to find line with no ^M at end and add one :map V v # recurse till 'n' fails type V or v to vi and watch the fun before your very eyes. Of course a 5 line C program would be quicker but who needs efficiency when you can watch vi do its stuff. The two tricks 1) using a register for the ^M and 2) using a preset search strings are necessary on the sun cos a ^M in a macro is taken to act as a and square brackets in a search string within a macro confused our version of vi. enjoy --alen the Lisa slayer (it's a long story) ...seismo!esosun!cogen!alen ps one good reason for wanting to perform this function is to prepare a text file for an os which demands at the end of each line.