UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 4.8 Making Directories Made Easier Chapter 4
Organizing Your Home Directory
Next: 4.10 Find All Command Versions with whereiz
 

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


Previous: 4.8 Making Directories Made Easier UNIX Power ToolsNext: 4.10 Find All Command Versions with whereiz
4.8 Making Directories Made Easier Book Index4.10 Find All Command Versions with whereiz

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System