Полезная информация

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 30.19 Modelines: Bug or Feature?Chapter 30
vi Tips and Tricks
Next: 30.21 Per File Setups in Separate Files
 

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


Previous: 30.19 Modelines: Bug or Feature?UNIX Power ToolsNext: 30.21 Per File Setups in Separate Files
30.19 Modelines: Bug or Feature?Book Index30.21 Per File Setups in Separate Files

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