10

I know from experience that the ~/.exrc file can be used to configure vim. I also know that the ~/.vimrc file can be used for the same purpose.

However, If I use .exrc to configure vim, this leads to problems on systems where vi is installed rather than vim. Namely, vim supports extra features that vi does not; and when you try to use them in vi, vi complains.

My questions are:

  1. What is the difference between .exrc and .vimrc?
  2. If both are present, then are both used?
  3. Is it bad practice to use the .exrc file to configure vim?
11
  1. .exrc is the configuration file for vi, whereas .vimrc is the config file for vim

  2. No. Vim will use the .vimrc file if present, otherwise the .exrc file if present

  3. Yes, unless you only put vi-compatible commands in there

From the Vim help on exrc:

 c. Four places are searched for initializations.  The first that exists
is used, the others are ignored.  The $MYVIMRC environment variable is
set to the file that was first found, unless $MYVIMRC was already set
and when using VIMINIT.
-  The environment variable VIMINIT (see also |compatible-default|) (*)
   The value of $VIMINIT is used as an Ex command line.
-  The user vimrc file(s):
        "$HOME/.vimrc"     (for Unix and OS/2) (*)
        "$HOME/.vim/vimrc"     (for Unix and OS/2) (*)
        "s:.vimrc"         (for Amiga) (*)
        "home:.vimrc"      (for Amiga) (*)
        "home:vimfiles:vimrc"  (for Amiga) (*)
        "$VIM/.vimrc"      (for OS/2 and Amiga) (*)
        "$HOME/_vimrc"     (for MS-DOS and Win32) (*)
        "$HOME/vimfiles/vimrc" (for MS-DOS and Win32) (*)
        "$VIM/_vimrc"      (for MS-DOS and Win32) (*)
    Note: For Unix, OS/2 and Amiga, when ".vimrc" does not exist,
    "_vimrc" is also tried, in case an MS-DOS compatible file
    system is used.  For MS-DOS and Win32 ".vimrc" is checked
    after "_vimrc", in case long file names are used.
    Note: For MS-DOS and Win32, "$HOME" is checked first.  If no
    "_vimrc" or ".vimrc" is found there, "$VIM" is tried.
    See |$VIM| for when $VIM is not set.
-  The environment variable EXINIT.
   The value of $EXINIT is used as an Ex command line.
-  The user exrc file(s).  Same as for the user vimrc file, but with
   "vimrc" replaced by "exrc".  But only one of ".exrc" and "_exrc" is
   used, depending on the system.  And without the (*)!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.