The previous lesson described text abbreviations, which are used in text mode to expand
an abbreviation into a full sequence of text. This lesson describes keyboard macros, which are used in command mode to devise editing shortcuts.
The :map
command lets you create shortcuts for editing tasks that are repetitive or hard to remember. With the :map
command, you
assign a sequence of vi commands to a single character. The result is a keyboard macro, also called a keyboard map or simply a map. The map acts like a new vi command but performs several things at a time. Conceptually, vi maps are similar to shell aliases. Both provide a shorthand for issuing more complex commands. The table below shows the general form of the related map commands:
Keyboard macro: A keyboard macro lets you perform a sequence of vi commands as a single keystroke. Keyboard macros also are called keyboard maps because they are created using the :map command.
Typically, you want to assign your map sequences to keys that are unused in command mode. That is because mapping a key overrides its regular command mode meaning. The following unused keys are available:
Letters and symbols: |
g K q V v _ * \ = |
Control characters: |
Ctrl-A , Ctrl-K , Ctrl-O , Ctrl-Z |
Some vi commands are rarely used, so you most likely could map these keys without missing their original functions. Among the rarely used keys are
f
,
F
,
t
,
T
,
z
, and
Z
.
In the next lesson, you will learn how to use the
:set
command to configure vi.