Lesson 4 | Creating text abbreviations |
Objective | Use 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:
- In vi, begin the :ab command, which drops your cursor to the status line.
- After entering the :ab command, continue editing the file. In text mode, change the word.
- After typing tsh and then a space, the text abbreviation is triggered.
- Return to command made by pressing Escape. Then enter :w to save your changes.
- By using the :ab command without arguments, it lists your current abbreviations.
- 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.