Re: Irregular character search and replace?



I was really looking for a general solution to dealing with 
control characters in the editor.

Some control characters can be entered into the search/replace
functions by first typing C-q before the the command.  C-q is the
literal operator.  Regrettably, when searching for C-M, the
search functions behave oddly.

But there is a decent solution at least to dealing with the
limited task of replacing C-M in a document by using the external
formatter function.  F19 (which is Shift-F7 on my system) invokes
an external editor.  At first invokation it creates
~/.mc/cedit/edit.indent.rc.  Modify the script to read as I have
it below.  Then select the text you wish to clean up using F3,
press F19, and all the carriage returns should be removed.
Obviously you can increase the functionality of the script on
your own.

I found a two-step hack that also works just using CoolEdit's
search/replace function.  First, search for C-J and replace with
aC-J (that's the character "a" immediately followed by ctrl-J)
with the scanf option unchecked.  Then search for C-Ja and
replace with nothing while the scanf option is checked.  That
process seems to retain the LFs where needed while eliminating
the CRs.  Bizarre, eh?

All the best, Don Livingston.

<begin script listing>

#! /bin/sh
# *** External Formatter (Indenter) for GNU Midnight Commander.
# arguments:
#    $1 - Name of the file being edited
#    $2 - Name of the file to be processed

exec >/dev/null

sed -i "s/\r//" $2

<end script listing>




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]