| Previous | Table of Contents | Next |
The .exrc File
The set options can be placed in the .exrc file so that each time vi is invoked the options are read and set automatically. The .exrc file may be placed in the user's HOME directory or the current working directory. The options set in .exrc will be overridden by the settings in the EXINIT variable if it exists.
An example .exrc file:
cj> cat .exrc
set ai | map v :w
set window=5
set wm=8
map Ctrl-Z :shCtrl-M
ab rf Robert Felps
These commands activate auto-indent (in the .exrc file | is equal to a new-line), map v to :w. Set the window size to 5 lines. The report line will be updated if 1 or more lines are modified. Set the right margin to 72; new-lines are inserted automatically. Map control-Z to an escape to a subshell key sequence. You must use Ctrl-V then Ctrl-M when creating the map. Abbreviate rf for Robert Felps.
You may save abreviations, maps, and set commands in any file. For ex/vi to read them during initialization the file must be named .exrc and reside in the current working directory. If the commands reside in another file, you can have ex/vi read the file at any time by using the following command.
so file
where file is the name of the file containing the commands.
The EXINIT Variable
The shell variable (EXINIT) can be assigned vi options. When vi is invoked the options are read and set inside vi. The EXINIT variable should be put in your .profile file so it is set when you log in. The EXINIT variable will override the .exrc file settings.
The EXINIT variable can be set as follows:
cj> EXINIT='set ai window=5 report=1 wm=8'
This command sets auto-indent, the window size to 5 lines, causes updates to the report line if 1 or more lines are modified, and sets the page width to 72 columns with auto-wrap margin.
DIAGNOSTICS AND BUGS
There are a few bugs or implementations of features that are worth noting.
The undo command (u) causes all marks to be lost on lines that were involved in the change.
The undo command never clears the modified buffer status.
No warning is given of text stored in named registers when you exit the editor.
The z command prints a logical number of lines, not the physical. Thus if you have long lines that wrap around the screen, the top lines of the screen may scroll off the visual terminal screen.
The NUL (octal 000) is discarded on input and thus cannot be entered in the buffer.
The new-line (012), Ctrl-J, character cannot be placed in the text as visual characters.
RELATED COMMANDS
Refer to the nawk, ed, sed, and vi commands described in modules 6, 39, 117, and 151.
RELATED FILES
The following list of files are used by ex/vi.
| /usr/lib/ex?.?strings | The error messages used by ex/vi |
| /usr/lib/ex?.?recover | The recover command |
| /usr/lib/ex?.?preserve | The preserve command |
| /usr/share/lib/terminfo/?/* | Terminfo database for terminal descriptions |
| $HOME/.exrc | The startup file used to store the ex/vi environment |
| ./.exrc | The startup file used to store the ex/vi environment |
| /tmp/EXnnnnn | Temporary buffer copy of the file |
| /tmp/Rxnnnnn | Temporary named register storage files |
| /var/preserve/login | Directory where preserved files are kept |
APPLICATIONS
The ex command is useful in performing editing functions that do not require full-screen viewing of the data. For example, global substitutions, file manipulation within the editor, macros, abbreviations, tags, and various other features are beneficial to the everyday requirements of editing.
TYPICAL OPERATION
In this activity you use the ex command to create and edit multiple files. Begin at the shell prompt.
cj> ex mypasswd mygroup
:0r /etc/passwd
:w %.bak
:s/:/ /g
NEWUSER::5000:50:New User:/u1/new/user:/bin/ksh . :
:arg [mypasswd] mygroup
| Previous | Table of Contents | Next |