- 论坛徽章:
- 0
|
command, and then restores the wrapmargin. Note that a
map sequence can combine ex and vi commands.
In the previous example, even though ^J is a vi command (it moves
the cursor down a line), this key is safe to map because it's really
the same as the j command. There are many keys that either
perform the same tasks as other keys or that are rarely used.
However, you should be familiar with the vi commands before you
boldly disable their normal use by using them in map definitions.
7.3.6 Mapping Keys for Insert Mode
Normally, maps apply only to command mode鈥攁fter all, in insert
mode, keys stand for themselves and shouldn't be mapped as
commands. However, by adding an exclamation mark (!) to the mapcommand, you can force it to override the ordinary meaning of a
key and produce the map in insert mode. This feature is useful
when you find yourself in insert mode but need to escape briefly to
command mode, run a command, and then return to insert mode.
For example, suppose you just typed a word but forgot to italicize it
(or place quotes around it, etc.). You can define this map:
:map! + ^[bi<I>^[ea</I>
Now, when you type a + at the end of a word, you will surround the
word with HTML italicization codes. The + won't show up in the text.
The sequence above escapes to command mode (^[), backs up to
insert the first code (bi<I>, escapes again (^[), and moves ahead
to append the second code (ea</I>. Since the map sequence
begins and ends in insert mode, you can continue entering text
after marking the word.
Here's another example. Suppose that you've been typing your text,
and you realize that the previous line should have ended with a
colon. You can correct that by defining this map sequence:[6]
[6] From an article by Walter Zintz, in UNIX World, April 1990.
:map! % ^[kA:^[jA
Now, if you type a % anywhere along your current line, you'll
append a colon to the end of the previous line. This command
escapes to command mode, moves up a line, and appends the colon
(^[kA. The command then escapes again, moves down to the line
you were on, and leaves you in insert mode (^[jA). |
|