Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 25 Jan 2004 10:17:53 -0500
From:      Dan Welch <welchdw@earthlink.net>
To:        marlon corleone <chkrootkit@hotmail.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: how to get rid of ^M character using vi
Message-ID:  <20040125151753.GA1798@gandalf.welch.net>
In-Reply-To: <BAY13-F62bUpm0RnzXo00012ad5@hotmail.com>
References:  <BAY13-F62bUpm0RnzXo00012ad5@hotmail.com>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
On Sun, Jan 25, 2004 at 09:43:21AM +0000, marlon corleone wrote:
> how do i get rid of this annoying character ^M using vi, in pico i used the 
> arguments '-w'
> but what about in vi?

This colon (ed) command works in FreeBSD's included vi's
command mode:

:%s/^M//g

followed by pressing Enter.  The ^M (or Ctrl-M) typed to
show it here should actually be entered by pressing ^v
^M in sequence. (The ^v preface tells vi to use the next
keystroke literally instead of taking it as a command.)

In a slight variation  you can take advantage the
replacement field in the substitution (which I left blank)
to produce a blank line between the original lines --
useful when the ^M marks the paragraph breaks:

:%s/^M/^M/g

It looks redundant, but after playing with the first version
you'll probably see what's going on.

You may also find the following short-cut useful for simpler
files:
:%s/^M
i.e., press Enter just after getting the ^M on the command
line, thus ending prematurely.  This works quite usefully
when the file has only one ^M per line and none embedded.



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?20040125151753.GA1798>