Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I remove new-lines [CR,LF] in vi?

2,323 views
Skip to first unread message

Ove Ruben R Olsen

unread,
Jul 20, 1992, 4:54:26 AM7/20/92
to
Sergio Stewart writes:
>How do I remove a CR,LF from a file while editing with vi?
>In the past Ive "dd" the entire line just to remove the CR,LF.
>I know it is possible to use "u" undo the CR,LF is still in the
>buffer, but what if it isnt? What Id like is a simple "x" [delete char]
>solution to removing CR and LF's.
>
>Any ideas?

To remove the CRLF at the end of a line: :%s/^V^M//
^
CTRL-V-CTRL-M

To remove blanklines (LF): :%s/^$//
^
NOT CTRL-$, but just ^ and $

To remove blanklines containing ^M (CRLF): :%s/^^V^M$//


\Ruben.


--
Ove Ruben R Olsen, Professional VI user. EMAIL: Ove.R...@ubb.uib.no
Maintaining the Largest VI/EX-STUFF Archive in the WORLD (alf.uib.no) and
the Comp.Editors FAQ file. If you have information about editing, new editors,
please get in touch with me. This does not apply to EMACS type of editors.

Sergio Stewart

unread,
Jul 19, 1992, 7:26:15 PM7/19/92
to
How do I remove a CR,LF from a file while editing with vi?
In the past Ive "dd" the entire line just to remove the CR,LF.
I know it is possible to use "u" undo the CR,LF is still in the
buffer, but what if it isnt? What Id like is a simple "x" [delete char]
solution to removing CR and LF's.

Any ideas?


--
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\\ Serge Stewart | ser...@x10siv.wariat.org \\
\\ -------------------------- | "Agony is born of Desire... \\
\\ Kansas City,Missouri 64130 | thats what you get for wanting" -Moev \\

Hans Mulder

unread,
Jul 20, 1992, 6:03:00 AM7/20/92
to
In <Brnt3...@x10siv.wariat.org> ser...@x10siv.wariat.org (Sergio Stewart) writes:
>How do I remove a CR,LF from a file while editing with vi?
>In the past Ive "dd" the entire line just to remove the CR,LF.

If there are any CRs in the buffer (vi shows those as ^M), you can use
"x" to get rid of them.

The easiest way to get rid of an LF is usually "J" (join lines).
Vi tries to be smart about "J" and give you the appropriate amount
of white space instead. If you don't want that, you can "x" it out
or use ":j!" instead of "J" to stop vi from generating it.

--
Hope this helps,

Hans Mulder ha...@cs.kun.nl

Lanfranco Albani

unread,
Jul 21, 1992, 5:35:58 AM7/21/92
to
bu...@alf.uib.no (Ove Ruben R Olsen) writes:
:To remove the CRLF at the end of a line: :%s/^V^M//
: ^
: CTRL-V-CTRL-M

Use: :%s/^V^M$//
just in case you have some strange file format (^M in middle...)

:To remove blanklines (LF): :%s/^$//


: ^
: NOT CTRL-$, but just ^ and $

Blank lines may have blanks and tabs, and they are not visible
unless you use :set list , so is better to use:
:%s/^[ ][ ]*$//
or
:%s/^[ ]+$//

Between square brackets there are a blank and a tab.


Bye, Lanfranco


--
Lanfranco Albani - CAD.LAB s.p.a., v. Ronzani 7/29, Casalecchio, Italia
Email: (work:) alb...@cadlab.sublink.org, (home:) b...@allan.sublink.org
Phone: (work:) ++39 (51) 6130360, (home:) ++39 (51) 727372;
Fax: ++39 (51) 6130294 (work only), Fidonet: 2:332/407.1138 (home only).

0 new messages