AIX Tip of the Week

AIX Tip of the Week: vi Editor Abbreviation an Map Commands

Audience: AIX Users

Date: September 24, 1999

The (abbreviate) and map commands are two little known, but useful vi editor functions. The abbreviate command allows you to create abbreviations that expand to full text in vi's insert mode. An example of the abbreviate command is

	:ab International Business Machines International Business Machines

When "International Business Machines" is typed in vi's insert mode, it automatically expands to "International Business Machines".

The map command allows you to assign actions to function keys and special characters. For example, the following map command defines the F1 key to reverse the order of two words.

	:map #1 dwelp

The "dwelp" characters are the vi keystrokes you would have used to reverse the order of two words. The F1 key now performans these keystrokes.

Typically ab and map assignments are stored in vi's startup profile ".exrc". The attached file, exrc.Z, provides a sample ".exrc" file illustrating how these commands might be used. This file makes the following assignments:

	F1 - Removes the DOS end of line character (^M) from all lines in a file
	F2 - Wraps the HTML < strong> and </strong> tags around a word
	F3 - Creates a C program skeleton:
		main(argc, argv)
			int argc;
			char *argv[];
	F4 - Reformats a paragraph
	abbreviate International Business Machines as ibm
International Business Machines is an abbreviation for International Business Machines.

Sample .exrc File

" Note:  enter control characters (Enter, ESC, etc) using the  
" -V escape sequence:  Example: to add Enter, type: -v 
" The following two lines show how the control characters were created
" ^[ = [Ctrl]-v [ESC]
" ^M = [Ctrl]-v [Enter]

" Remove DOS end of line characters
map #1 :%s/^M//

" Add HTML < strong>  tags around word
map #2 ^[i< strong> ^[Ea< /strong> ^[

" Add multiline C program construct
map #3 ^[i#include ^Mmain(argc, argv) ^M	int argc;^M	char #argv[];^M{^M}^M^[

" Format paragraph
map #4 ^[:.,/^$/!fmt^[

ab ibm International Business Machines