vi provides two ways to decrease the amount of typing you have to do: abbreviations and maps.
Word Abbreviation
:ab abbr phrase
:ab
:unab abbr
Command and Input Mode Maps
:map x sequence
:unmap x
:map
:map! x sequence
:unmap! x
:map!
For both command and insert mode maps, the map name x can take several forms:
One character
Multiple characters
# n
# followed by a digit n represents the sequence of characters sent by the keyboard’s function key number n.To enter characters such as Escape (
^[) or carriage return (^M), first type CTRL-V (^V).Executable Buffers
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
:@buf-name works similarly.Some versions of vi treat
* identically to @ when used from the ex command line. In addition, if the buffer character supplied after the @ or * commands is *, the command is taken from the default (unnamed) buffer.Automatic Indentation
Enable automatic indentation with the following command:
:set autoindent
Four special input sequences affect automatic indentation:
^T
^D
^ ^D
0 ^D
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.

Help


