vi provides two ways to decrease the amount of typing you have to do: abbreviations and maps.
:ab abbr phrase
Command and Input Mode Maps
:map x sequence
:map! x sequence
For both command and insert mode maps, the map name x can take several forms:
#followed by a digit
nrepresents the sequence of characters sent by the keyboard’s function key number
To enter characters such as Escape (
^[) or carriage return (
^M), first type CTRL-V (
Named buffers provide yet another way to create “macros”—complex command sequences you can repeat with a few keystrokes. Here’s how it’s done:
- Type a vi command sequence or an ex command preceded by a colon; return to command mode.
- Delete the text into a named buffer.
- Execute the buffer with the @ command followed by the buffer letter.
The ex command
Some versions of vi treat
@when used from the ex command line. In addition, if the buffer character supplied after the
*, the command is taken from the default (unnamed) buffer.
Enable automatic indentation with the following command:
Four special input sequences affect automatic indentation:
Two commands can be used for shifting source code:
The default shift is the value of
shiftwidth, usually eight spaces.
Learn more about this topic from vi and Vim Editors Pocket Reference, 2nd Edition.
Many Unix, Linux, and Mac OS X geeks enjoy using the powerful, platform-agnostic text editors vi and Vim, but there are far too many commands for anyone to remember. Author Arnold Robbins has chosen the most valuable commands for vi, Vim, and vi's main clones—vile, elvis, and nvi—and packed them into this easy-to-browse pocket reference. You'll find commands for all kinds of editing tasks, including programming, modifying system files, writing and marking up articles, and more.