[Chapter 4] 4.9 Setting Up vi with the .exrc File
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:32:45Z

#

| Chapter 4 Organizing Your Home Directory |

## 4.9 Setting Up vi with the .exrc File

You can store commands and settings that you want executed any time you start the vi or ex editors (30.2) in a file called .exrc in your home directory. You can modify the .exrc file with the vi editor, just as you can any other text file.

If you don't yet have an .exrc file, simply use vi to create one. Enter into this file the set, ab (30.31), and map (31.2) commands that you want to have in effect whenever you use vi or ex. A sample .exrc file looks like this:

>     set nowrapscan wrapmargin=7
>     set sections=SeAhBhChDh nomesg
>     map q :w^M:n^M
>     " To swap two words, put cursor at start of first word and type v:
>     map v dwElp
>     ab ORA O'Reilly & Associates, Inc.

The `^M` characters are RETURNs. Make them by pressing CTRL-v, then RETURN (31.6). Lines that start with a double quote (`"`) are comments. Since the file is actually read by ex before it enters vi, commands in .exrc should not have a preceding colon.

In addition to reading the .exrc file in your home directory, vi will read a file called .exrc in the current directory. This allows you to set options that are appropriateto a particular project . (30.6)

If your .exrc file doesn't seem to be working, watch carefully for error messages just as vi starts, before it clears your screen. If you can't read them quickly enough, start ex instead of vi. The q! command quits ex:

>     % ex
>     No tail recursion
>     :q!

The tricks in article 42.8 may also be useful.

- TOR from O'Reilly & Associates' Learning the vi Editor, Chapter 7

4.8 Making Directories Made Easier |  | 4.10 Find All Command Versions with whereiz