How would one delete select control characters

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How would one delete select control characters

Nathan Steward
Hi all,

I am happy to find this excellent resource. I would like
to ask if anyone has figured out a method to remove
certain control characters from a file. For example,
can I yank a control character into a buffer, and then
use that buffer in a command to delete all instances
of that particular character? Often, I am not aware of
what sequences made the character, or I would use the
same expression that is used to delete ^Ms.

thanks very much,

Nathan

Reply | Threaded
Open this post in threaded view
|

Re: How would one delete select control characters

James Vega-3
On Mon, Aug 08, 2005 at 01:47:16PM -0400, Nathan Steward wrote:

> Hi all,
>
> I am happy to find this excellent resource. I would like
> to ask if anyone has figured out a method to remove
> certain control characters from a file. For example,
> can I yank a control character into a buffer, and then
> use that buffer in a command to delete all instances
> of that particular character? Often, I am not aware of
> what sequences made the character, or I would use the
> same expression that is used to delete ^Ms.
You've already guessed at what I feel is the easiest way.  Yank the
character and then paste it in the commandline using <C-r>"

:he c_ctrl-r

HTH,
James
--
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[hidden email]>

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How would one delete select control characters

Tim Chase-2
In reply to this post by Nathan Steward
> I am happy to find this excellent resource.

> I would like to ask if anyone has figured out a method to
> remove certain control characters from a file.

It sounds like you simply want to zap the control-characters from
your file, for which you should be able to use

        :%s/[[:cntrl:]]//g

which will simply remove all the control characters (except for
newlines, of course) from your file.

There are a number of character classes, found at ":help
[:alnum:]" which can be used to simply specify such characters.
You can also use inverse sets, so if you want to nuke anything
that's not printable, you can use

        :%s/[^[:print:]]//g

This method should also work if you want to use them in a regular
expression for other means (such as "wrap every control character
in square brackets" which would be

        :%s/[[:cntrl:]]/[&]/g

Hope this helps,

-tim