A sample .exrc file for vi editor users
 

Introduction

This article presents a sample .exrc file that can be used by users of the vi editor.  The .exrc file, located in your home directory, is the startup (or configuration) file for the vi editor.

The intent of this brief article is to show some of the ways you can modify the configuration of the vi editor.
 

Brief discussion

Listing 1 shows our sample .exrc file. In this file we've changed the definition of some of the keystrokes within the editor.  Note that map commands are used to map keystrokes.  By configuring this .exrc file, we've mapped many of the function keys on your keyboard, including <F1>, <F2>, ... <F9> (with the exception of <F4>).

Note that the <F1> key is mapped to run a more command on a file named .vi_help.  The .vi_help file is shown in Listing 2.  It's just a plain text file that provides some "help" for users of the vi editor.  When you hit the <F1> key, this file will be displayed (if properly installed in your home directory).

The <F2> key is now programmed to displayed line numbers when you select it.  <F3> performs the opposite function - it hides the line numbers, so these two keystrokes are essentially toggle switches for the number display.
 
 

 
Listing 1:    exrc - a sample .exrc file for users of the vi editor 
 

Note that Listing 1 may appear a little unusual. That's because it includes control characters (such as ^V and ^M) that may not print properly on screen. If you download the .exrc file using the link shown at the end of this article, the file will be downloaded with these control characters, which it needs to work properly.


 
 

 
Listing 2:  .vi_help - This file is displayed when the user hits the <F1> function key.  Both this file and the .exrc file shown in Listing 1 must be installed in the user's home directory. 
 
 

Installation and comments

If you're interested in seeing how the .exrc and .vi_help files affect your version of the vi editor, just download the files using the links shown below. After you've downloaded the files, just copy them to your home directory. (As always, if you have files with these same names in your home directory already, make a backup copy of them before installing these files.)

Once you've installed these files in your home directory, just start the vi editor, and try using the various function keys that we've defined.

Other commands that readers have recommended:

Download the files

If you'd like to download these files, just click on the links below.  After you click on each file, just select File|Save As... from your browser to save the .profile to your local filesystem.