[Chapter 30] 30.20 Multiple Editor Setup Files; Starting with a Search
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:45:34Z

#

| Chapter 30 vi Tips and Tricks |

## 30.20 Multiple Editor Setup Files; Starting with a Search

[This article shows vi, but the same thing will work for other editors that read a setup file when they start up. -JP]

Like many people, I want different vi options set for writing a program than for working on a text file. Here's how I do it.

Instead of putting mode lines (30.19) within each file, or writing extensions to the filenames (30.21), I've got several different .exrc (30.6) startup files... one for each vi mode I'd like to use. I have aliases (10.2) that let me select the .exrc file I want. And I have vi aliased so that, when I start it up, it tells me which .exrc file is in use. Here are the lines (with comments) from my .cshrc (2.1) file (the CD-ROM has a set for Bourne-type shells):

    ~ setenv

    \!*
    sleep
    setenv EXSTAT text        # INITIALIZATION FOR 'vi' ALIAS

            # -- THESE ALIASES RESET THE .exrc FILE -- #
    # SET 'vi' FOR 4-CHARACTER TABS/SHIFTS:
    alias 4vi 'cp ~/lib/vi/exrc4 ~/.exrc; setenv EXSTAT programming'
    # SET 'vi' FOR 8-CHARACTER TABS/SHIFTS:
    alias 8vi 'cp ~/lib/vi/exrc8 ~/.exrc; setenv EXSTAT text'
    # SET 'vi' FOR QUICK WORK WHEN SYSTEM IS SLOW (NO .exrc FILE):
    alias qvi 'rm ~/.exrc; setenv EXSTAT quick'

       # -- THESE ARE THE vi ALIASES. ONE SETS THE vi MODE FIRST -- #
    alias vi 'echo "MODE: $EXSTAT"; sleep 1; /usr/ucb/vi \!*'
    # CALL vi WITH A SEARCH:
    alias vs '8vi; vi +/\!*'

The EXSTAT variable remembers which setup file has been stored in the .exrc file. Also, because you can't start vi with a search (`vi +/PATTERN`) unless the wrapscan option has been set... so, I start the vs alias with an `8vi` because my exrc8 file sets wrapscan. Here's an example. I'll edit the file report and search for a line that has the word misteak:

>     % vs misteak report
>     MODE: text
>     "report" 45 lines, 2734 characters

- JP

30.19 Modelines: Bug or Feature? |  | 30.21 Per File Setups in Separate Files