2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
9 static char sccsid
[] = "$Id: ex_map.c,v 8.4 1993/11/27 15:52:30 bostic Exp $ (Berkeley) $Date: 1993/11/27 15:52:30 $";
12 #include <sys/types.h>
23 * ex_map -- :map[!] [input] [replacement]
24 * Map a key/string or display mapped keys.
27 * Historic vi maps were fairly bizarre, and likely to differ in
28 * very subtle and strange ways from this implementation. Two
29 * things worth noting are that vi would often hang or drop core
30 * if the map was strange enough (ex: map X "xy$@x^V), or, simply
31 * not work. One trick worth remembering is that if you put a
32 * mark at the start of the map, e.g. map X mx"xy ...), or if you
33 * put the map in a .exrc file, things would often work much better.
47 stype
= F_ISSET(cmdp
, E_FORCE
) ? SEQ_INPUT
: SEQ_COMMAND
;
51 if (seq_dump(sp
, stype
, 1) == 0)
52 msgq(sp
, M_INFO
, "No %s map entries.",
53 stype
== SEQ_INPUT
? "input" : "command");
56 input
= cmdp
->argv
[0];
57 output
= cmdp
->argv
[1];
64 * If the mapped string is #[0-9] (and wasn't quoted in any
65 * way, then map to a function key.
67 if (input
[0] == '#' && isdigit(input
[1]) && !input
[2]) {
68 key
= atoi(input
+ 1);
69 (void)snprintf(buf
, sizeof(buf
), "f%d", key
);
71 if (FKEY
[key
]) { /* CCC */
75 msgq(sp
, M_ERR
, "This terminal has no %s key.", buf
);
84 /* Some single keys may not be remapped in command mode. */
85 if (stype
== SEQ_COMMAND
&& input
[1] == '\0')
86 switch (sp
->special
[input
[0]]) {
92 "The %s character may not be remapped.",
93 charname(sp
, input
[0]));
97 return (seq_set(sp
, name
, input
, output
, stype
, 1));
101 * ex_unmap -- (:unmap[!] key)
105 ex_unmap(sp
, ep
, cmdp
)
112 input
= cmdp
->argv
[0];
114 input
, F_ISSET(cmdp
, E_FORCE
) ? SEQ_INPUT
: SEQ_COMMAND
)) {
115 msgq(sp
, M_INFO
, "\"%s\" isn't mapped.", input
);
123 * Save the mapped sequences to a file.
130 if (seq_save(sp
, fp
, "map ", SEQ_COMMAND
))
132 return (seq_save(sp
, fp
, "map! ", SEQ_INPUT
));