[comp.editors] Side effects of mapping

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

Okay, take one of the vi commands that will replace all occurences
of _^H (underscore, backspace) in a file.  Something like this will
do it:

:%s/_^H//g
(NB, to get the ^H I escaped it with ^V)

But supposing you want to map this to a specific key?  I tried this line:

:map D :%s/_^H//g

But when I typed 'D' the editor responded with:

:%s///g

Which is not going to work.  The ^H acted as a literal rubout and erased the
underscore leaving an empty replacement string.  Okay, the next thing I tried
was this:

:map D :%s/_^V^H//g
(NB, I type ^V^V^V^H to get a literal ^V^H combination)

But the same thing happens when I type 'D again:

:%s///g

Which is to say that when interpreting a mapping, VI ignores the ^V (or
at least does not consider that an escape key.  Does anybody have any
ideas how to get around this?  I've tried using various combinations of
^V and \ before the ^H, but nothing seems to work...

Cheers!
Bharat

-- 
+------------------+------------------------------------------------------+
| Bharat Mediratta | bharat@cm.cf.ac.uk                                   | 
+------------------+------------------------------------------------------+
|                                                                         |

maart@cs.vu.nl (Maarten Litmaath) (02/02/91)

In article <1991Feb1.125430.2829@computing-maths.cardiff.ac.uk>,
	bharat@computing-maths.cardiff.ac.uk (Bharat Mediratta) writes:
)[...]
):map D :%s/_^V^H//g
)(NB, I type ^V^V^V^H to get a literal ^V^H combination)

You need more ^V characters!

	:map D :%s/_^V^V^H//g
		    ^^^^^^
		    typed as ^V^V^V^V^V^H

The map is interpreted once when it is set and once when it is invoked,
hence _two_ levels of ^V escaping will be stripped.
--
"Salman Rushdie received a copy just as his latest novel was being published.
He ignored it and received myriads of death threats. He quickly decided to
send out twenty copies (some to the Ayatollah) and is still alive."
			(John Banagan <jvbanagan@ucdavis.edu> in sci.skeptic)

dattier@gagme.chi.il.us (David W. Tamkin) (02/04/91)

kapil@zarquon.uchicago.edu (Kapil Paranjape) wrote in
<1991Feb2.170202.12914@midway.uchicago.edu>:

| A similar thing happens if you try to map in the .exrc file
| 	:map T 75|some-other-muck
| the | is interpreted as a command seperator/pipe by ex and *not*
| as it was intended to --- a "column" command. The same line is accepted
| within vi though! Some inconsistent behavior here.
| Various quote attempts like ^V and \ do not work either.

I had the same problem and got around it as follows, but I cannot recall
whether I stumbled onto the solution fortuitously or read it in comp.editors
when someone else asked the same question:

" type ctrl-V ctrl-V pipe
:map T 75^V|some-other-muck

where you've typed ^V twice when you put the mapping into your .exrc so that
one caret and one capital V are visible.

If that came from this noozfroop, thanks to whoever posted it.

David W. Tamkin  Box 7002  Des Plaines IL  60018-7002  dattier@gagme.chi.il.us
708 518 6769  312 693 0591  GEnie:D.W.TAMKIN  CIS:73720,1570  MCIMail:426-1818