DistributedNetworks DistributedNetworks

vi editing  «Prev  Next»
Lesson 4 Creating text abbreviations
ObjectiveUse the :ab command to abbreviate text.

Creating text abbreviations (vi)

Because editing can be repetitive, you may find yourself typing common phrases over and over again.
For example, I sing in a quartet named Town Square Harmonizers, but it is inconvenient to constantly type our name in a file.
I can avoid repeatedly typing the name if I use the :ab command to save a sequence of text as an abbreviation, like this:
:ab tsh Town Square Harmonizers
From now on, whenever I am in text mode and I type the 'word' tsh, vi automatically expands it to Town Square Harmonizers. I say 'word' because abbreviations are not expanded until you type them as you would a regular word--with a space or punctuation mark after the abbreviation.
The table below shows the general form of the related abbreviation commands:

Command Description
:ab short long Define short as an abbreviation for long
:ab List your currently defined abbreviations
:unab short Turn off the definition for short

The following SlideShow shows some examples:
Text 1
1) In vi, begin the :ab command, which drops your cursor to the status line.
Text 2
2) After entering the :ab command, continue editing the file. In text mode, change the word.
Text 3
3) After typing tsh and then a space, the text abbreviation is triggered.
Text 4
4) Return to command made by pressing Escape. Then enter :w to save your changes.
Text 5
5) By using the :ab command without arguments, it lists your current abbreviations.
Text 6
6) If you quit vi, you lose any abbreviations that you defined during the session.

Click the link below to see a list of Text Abbreviations.
Text Abbreviations
In the next lesson, you will learn how to create keyboard macros with the :map command.