[lug] Adding newline in vi

D. Stimits stimits at idcomm.com
Sat Aug 18 17:48:42 MDT 2001


John Starkey wrote:
> 
> > :%s/N/^M/g
> >
> > where ^M is generated by typing Ctrl-V <Enter> or by Ctrl-V Ctrl-M
> 
> Now I'm really confused. Six months ago you guys showed me how to get rid of the ^M chars in a doc using vi (doing the reverse of the above). I thought they were the CR/LF chars from MS docs.

If you are in vi, and do this:
:set list
(reverse this with :set nolist)
...then you will see $ as end of line via '\n', and ^M via '\r'. The
sequence "[ctrl v][enter]" gives you UNIX style end of line, while
"[ctrl v][ctrl m]" gives you the carriage return portion of DOS style
EOL. A ^M all by itself is a Mac style EOL. So in the above, maybe you
want to use [ctrl v][enter] rather than [ctrl v][ctrl m].


> 
> Why would deleting them from a document (when they are visable) have no effect on the returns but adding them would? And why would they only be visible half the time? Is vi seeing them as MS CR/LF and interpretting them as returns but not using them, just showing them so you are aware they exist?


How they are used depend on the application. For example, many
postscript printers appear to use plain text in their engines, but if
you strip the carriage return and it becomes UNIX style, it'll
mysteriously fail. Some editors (I think nedit) will try to detect what
style is used, and attempt to emulate or remain in that style throughout
editing, others blindly follow one convention or another during new
editing. Among those that auto-detect, they usually display right no
matter what; among those that blindly follow one convention during
editing, they might always display correctly anyway...and others might
have a stair-stepping look or extra lines if they don't display
correctly under all formats.

D. Stimits, stimits at idcomm.com

> 
> Thanks,
> 
> John
> 
> --
> John Starkey
> ColoradoParks.net
> Advance Creations
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug



More information about the LUG mailing list