gbergman@ucbtopaz.CC.Berkeley.ARPA (10/29/84)
Apologies for saying that ^V^V^V^M would not give the desired effect
of inserting a newline in a vi :map! command. It will, though
^V^M will do it as well. Here is the general scheme as well as I've
been able to figure it out:
in :map! escapes special
command, interpretation
typing: at the level: of characters:
^V writing command your delete & kill; ab.t;
line ^W, ^V, ^M, ^[, ^\
^V^V processing of space, tab, |, ^V
command
^V^V^V^V insertion your delete & kill; ab.t;
into text ^W, ^V, ^M, ^[, ^\
(here by "ab.t" I mean "abbreviation terminator", for example, any
nonalphanumeric character following an alphanumeric abbreviation.)
So before ^M, a single ^V will escape the interpretation of ^M
as carriage-return at the level of writing the command, i.e. will
allow you to include it in the command; an additional two ^V's
(contrary to what I said) will have no effect, since ^M does not
seem to be "special" at the command processing level; and it takes
four ^V's to escape its special interpretation at the level of
insertion into text. So with either 1 or 3 ^V's, it will be
included in the map! command, and produce the effect of a carriage
return in the inserted text, while with 5 or 7 ^V's it will produce
an inserted ^M in the text.
For constrast, consider the "substitute" command (with "magic"
set):
in :s escapes special
command, interpretation
typing: at the level: of characters:
^V writing command your delete & kill; ab.t;
line ^W, ^V, ^M, ^[, ^\
_
| pattern delimiter, \, ., ^, $, ~, [
\ -| [string] ^, \, -, ]
|_ replacement delimiter, \, &, ~, ^M
(Here by "delimiter" I mean the character you type immediately
after the s, typically /.) So if you type in s/x/^V^M, then you will
see this as s/x/^M, and when you type the final carriage return, x
in your text will be replaced by a newline, while if you type in
s/x/\^V^M you will see s/x/\^M, and when you hit another carriage
return, x will be replaced by an inserted ^M.
Apologies again for having sent that "correction" without testing
or thinking through what I was saying.
(The above is not, of course, complete. I haven't spoken of the
impossibility of escaping ^@ or linefeed, the special case of \ escaping
^H in text, the positive effect of \ in various "magic" combinations,
what happens if your map!ing includes an ^[... . And since much of the
above was discovered by trial and error, I'm sure there is much more to
be learned.)
George Bergman
Math, UC Berkeley 94720 USA
...!ucbvax!gbergman%cartan