ex allows you to map function keys by number, using the syntax:
:map #1 commands
for function key number 1, and so on.
(It can do this because the
editor has access to the entry for that terminal found in either the
terminfo or termcap database and knows the
escape sequence normally put out by the function key.)
As with other keys, maps apply by default to command mode, but by
using the map! commands as well, you can define two separate
values for a function key—one to be used in command mode, the other in
insert mode.
For example, if you are an HTML user, you might
want to put font-switch codes on function keys.
For example:
:map #1 i<I>^[
:map! #1 <I>
If you are in command mode, the first function key will enter insert
mode, type in the three characters <I>, and return to command mode.
If you are already in insert mode,
the key will simply type the
three-character HTML code.
NOTE:
If function keys have been redefined in the terminal's setup
mode, the #n
syntax might not work since the function keys no longer put
out the expected control
or escape sequence as described in its terminal database entry.
You will need to examine the terminfo source
(or termcap entry)
for your terminal and check the definitions for the function keys.
In addition, there are some terminals whose function keys perform only
local actions and don't actually send any characters to the computer.
Such function keys can't be mapped.
The terminal capabilities k1, k2
through k0 describe the first ten function keys.
The capabilities l1, l2 through
l0 describe the remaining function keys.
Using your terminal's setup mode, you can change the control
or escape sequence output by the function key to correspond with
the terminfo or termcap entry.
(For more information, see termcap & terminfo,
published by O'Reilly & Associates.)
If the sequence contains ^M, which is a carriage return,
press
CTRL-M.
For instance, in order to have function key 1 available for
mapping, the terminal database entry for your terminal must
have a definition of k1, such as:
k1=^A@^M
In turn, the definition:
^A@^M
must be what is output when you press that key.
To see what the function key puts out, use the od (octal dump)
command with the -c option (show each character).
You will need to press
RETURN
after the function key, and then
CTRL-D
to get od to print the information.
For example:
$ od -c
^[[[A
^D
0000000 033 [ [ A \n
0000005
Here, the function key sent Escape, two left brackets,
and an A.