[comp.editors] How do a write a specific macro in vi

rajkumar@plains.NoDak.edu (A. Joseph Rajkumar) (01/30/91)

Hi

  Using vi, I want to be able to do the following:-

I need to globally remove all control-H in a file, and also all the
underscores (_) in a file. 

  I used a map to map a "K" like this "map D :1,$ s///g" in my .exrc
file, but then when I try to edit a file which has these control-H,
I am not able to do it.

  I run into this problem when I use "refer" to include references into
a document. Also when I use the correct syntax for refer like this:-
refer -e -l4,2 database filename
I am getting the references included in the file as [BERN89a] etc, when
there is only on BERN reference. It is supposed to include the suffiz
'a' only when there are multiple BERN89's.

Thanks
Joseph Rajkumar
email:- rajkumar@plains.NoDak.edu

wyle@inf.ethz.ch (Mitchell Wyle) (01/30/91)

In <7829@plains.NoDak.edu> rajkumar@plains.NoDak.edu (A. Joseph Rajkumar) asks:

>  I used a map to map a "K" like this "map D :1,$ s/_^H//g" in my .exrc
>file, but then when I try to edit a file which has these control-H,
>I am not able to do it.

Escape the ^H with a ^V as in:  map D :%s/_^V^H//g

>refer -e -l4,2 database filename
>I am getting the references included in the file as [BERN89a] etc, when
>there is only on BERN reference. It is supposed to include the suffiz
>'a' only when there are multiple BERN89's.

But refer gives you troff code, n'est-ce pas?  You're not including roffbib
output in a document are you?

I've seen this refer problem before also; my paper went to an acm conference
which wanted numbered references, so I never found out how to fix it.

If the paper had been rejected, and I had to re-submit it to an IEEE
conference, I would probably be able to help you now :-]

One solution is to get a PD refer(1) somewhere.  Is the BSD4.4 refer free of
AT&T code?


Another solution is to use TeX and BibTeX.

>Joseph Rajkumar

--
Mitchell F. Wyle
Institut fuer Informationssysteme         wyle@inf.ethz.ch 
ETH Zentrum / 8092 Zurich, Switzerland    +41 1 254 7224

bharat@computing-maths.cardiff.ac.uk (Bharat Mediratta) (01/30/91)

In article <7829@plains.NoDak.edu> rajkumar@plains.NoDak.edu (A. Joseph Rajkumar) writes:
>  Using vi, I want to be able to do the following:-
>
>I need to globally remove all control-H in a file, and also all the
>underscores (_) in a file. 
>

This is a problem I have when I try to look at man pages in a
text editor.  I find a line like this works in vi:

:1,$s/[_^H]//g

N.B.  to get the ^H character type control-v control-h.

This will eliminate all occurences of underscore or backspace, no matter
where they are in the file (ie, they can be separated.)  This might
cause problems if there is a legitimate use of the underscore character
somewhere in the file.  If you want to remove the _^H construct (popularly
used for on-screen underlining on some machines) try this:

:1,$s/_^H//g

This will remove them only when they are together, not when they are separated.

Bharat

+------------------+------------------------------------------------------+
| Bharat Mediratta | bharat@cm.cf.ac.uk  |  mediratb@p4.cs.man.ac.uk      |
+------------------+------------------------------------------------------+
|                                                                         |
|   (@@@@)    /-----------------------\  "On a clear disk you can seek    |
|  (@@@@@@)   | I'm Bharat Simpson!   |      forever..."                  |
|  (@@@@@@)   | Don't Eat a Cow, Dude!|                                   |
|  |      |   \-----------------------/                                   |
|  | (o)(o)   /                                                           |
|  C      _) /    "When the going gets weird, the weird turn pro"         |
|   | ,___| -                          - Hunter S. Thompson               |
|   |   /                                                                 |
|  /____\         "You want it all, but you can't have it"                |
| /      \                             - Faith No More                    |
+-------------------------------------------------------------------------+
-- 
+------------------+------------------------------------------------------+
| Bharat Mediratta | bharat@cm.cf.ac.uk  |  mediratb@p4.cs.man.ac.uk      |
+------------------+------------------------------------------------------+
|                                                                         |

cadman@cbnewsm.att.com (jerome.schwartz) (01/31/91)

>   Using vi, I want to be able to do the following:-
> 
> I need to globally remove all control-H in a file, and also all the
> underscores (_) in a file. 
> 
>   I used a map to map a "K" like this "map D :1,$ s///g" in my .exrc
> file, but then when I try to edit a file which has these control-H,
> I am not able to do it.


The trick is to backslash the crtl-v before the crtl-h.

:map z :1,$s/_\^V^H//g^V^M

Try it you'll like it.....

Jerry
**********************************************************************
Jerome Schwartz               | Standard Disclaimer:
AT&T Bell Laboratories        |
600 Mountain Ave.             | Views expressed are my own and
Murray Hill, N.J.  07974-2070 | do not necessarily reflect those
Phone  : (201)-582-3070       | of my employer.
**********************************************************************

les@chinet.chi.il.us (Leslie Mikesell) (02/01/91)

In article <7829@plains.NoDak.edu> rajkumar@plains.NoDak.edu (A. Joseph Rajkumar) writes:

>I need to globally remove all control-H in a file, and also all the
>underscores (_) in a file. 

I suspect that you really want to remove any character followed by
a control-H.  This will also fix boldfacing done by overstriking.

>  I used a map to map a "K" like this "map D :1,$ s///g" in my .exrc
>file, but then when I try to edit a file which has these control-H,
>I am not able to do it.

The trick here is to provide enough ^V quoting for the number of times
that vi will parse it.  That is, you need one actually in the .exrc
file so you must type three of them. 
I probably wouldn't bother with something as simple as:
:%s/.^H//g
but if I have some larger set of ex commands to execute regularly, I
will put them in a file and execute with :so file instead of overloading
the .exrc which is always read whether you need it or not.

Les Mikesell
  les@chinet.chi.il.us

bharat@computing-maths.cardiff.ac.uk (Bharat Mediratta) (02/04/91)

In article <1104@gagme.chi.il.us> grahj@gagme.chi.il.us (jim graham) writes:
>In article <1991Jan31.202742.13674@chinet.chi.il.us> les@chinet.chi.il.us (Leslie Mikesell) writes:
>>In article <7829@plains.NoDak.edu> rajkumar@plains.NoDak.edu (A. Joseph Rajkumar) writes:
>>
>>>I need to globally remove all control-H in a file, and also all the
>>>underscores (_) in a file. 
>>
>>I suspect that you really want to remove any character followed by
>>a control-H.  This will also fix boldfacing done by overstriking.
>
>If in fact you are trying to remove all of the bold text and underlining
>(say, for example, as produced by nroff), there is a much easier way. 
>
>Save yourself the trouble.  Some time ago, a program called ``pep'' was 
>posted to one of the .sources groups (don't know which one).  This program 
>does a lot of things to ``clean'' text files, including taking out all of
>the boldfacing and underlining w/o hurting your real text. 
>

For Unix users out there, there is an easier way.  There is a program called
'plain' that comes with most systems.  Simply cat a file through it and
it removes the underscores for you.  I find it effective, especially if you
don't want to worry about search/replace functions.  This program is not
as flexible (no doubt) as 'pep' but it might be more universally available.

Cheers!
Bharat
-- 
+------------------+------------------------+
| Bharat Mediratta | bharat@cm.cf.ac.uk     |
| "On a clear disk you can seek forever..." |
+-------------------------------------------+

lee@sq.sq.com (Liam R. E. Quin) (02/08/91)

>>>>I need to globally remove all control-H in a file, and also all the
>>>>underscores (_) in a file. 
>>>
>>>I suspect that you really want to remove any character followed by
>>>a control-H.  This will also fix boldfacing done by overstriking.
If (like me) you have neither ``plain'' nor ``pep'', (I'd expect the latter
to be a comms package from Telebit!), don't despair.

You can use the filter "col -b" to do just this:
	1G!Gcol -b
works fine from within vi, for example.

Deleting control-h and _ in vi is also easy, of course:
	:%s/[^H_]//g
(you have to type control-V control-H tp get the ^H in there, of course)

Lee

-- 
Liam R. E. Quin,  lee@sq.com, SoftQuad Inc., Toronto, +1 (416) 963-8337