vi editing  «Prev  Next»
Lesson 7 Storing custom settings for vi
Objective Use the .exrc file to store vi settings

Storing custom settings for vi

When you define new text abbreviations, keyboard maps, or configuration options within a vi session, the custom settings are valid only for that session. Once you quit vi, the changes are lost. You can make your settings permanent by saving your :ab, :map, and :set commands in a configuration file called .exrc, which must reside in your home directory. The .exrc file is similar in concept to .cshrc, the configuration file for the C shell. When you start vi, it checks your .exrc file and runs any commands it finds there. This makes your custom vi settings available every time you use vi.
You can still change your settings within vi, but remember that changes you make within a session are temporary. When you quit vi and start it again, vi reverts to whatever settings are defined in the .exrc file.

Guidelines for editing your

.exrc file The following pointers will help you edit your .exrc file:
  1. Make sure there are no blank lines, because anything below the first blank line will be ignored.
  2. You may use the forms ab, map, and set because commands in an .exrc file are not required to begin with a colon (:).
  3. You may define multiple options using a single set command. For example, in your .exrc file, you can type a single line that reads, set ic showmode. The following MouseOver shows a sample .exrc file:

The relationship between eBusiness and eCommerce
  1. After creating an .exrc file (using vi, for example), you can use the cat .exrc command to display the contents. Whenever vi is started, it reads the .exrc file
  2. Using the ab command, you can define two text abbreviations, ec1 and tsh, which can prevent repeated typing of long phrases.
  3. With the map command, you can define the V key to transpose two words. The v key also can be defined as a shortcut to :wq.
  4. Two configuration options have been defined with a single set command. showmode tells you you are in text mode, and wrapmargin=7 tells the cursor to wrap around, or move to the beginning of the next line, when the cursor gets within 7 characters of the right margin.
  5. The set ic command causes text searches to ignore case, or treat uppercase and lowercase letters the same.

sample exrc file
In the next lesson, you will learn how to edit multiple files in the same vi session.

Storing Custom Settings-for Vi- Exercise

Click the Exercise link below to practice creating an .exrc file.
Storing Custom Settings-for Vi- Exercise