Where is my .vimrc file?

These methods work, if you already have a .vimrc file:

:scriptnames list all the .vim files that Vim loaded for you, including your .vimrc file.

:e $MYVIMRC open & edit the current .vimrc that you are using, then use Ctrl + G to view the path in status bar.


As additional information, mostly in macOS, the .vimrc file is located at directory:

/usr/share/vim/.vimrc

Short answer:

To create your vimrc, start up Vim and do one of the following:

:e $HOME/.vimrc  " on Unix, Mac or OS/2

:e $HOME/_vimrc  " on Windows

:e s:.vimrc      " on Amiga

Insert the settings you want, and save the file.

Note that exisitence of this file will disable the compatible option. See below for details.

Long answer:

There are two kinds of vimrc:

  • the user vimrc in $HOME
  • the system vimrc in $VIM (on Amiga systems, s:.vimrc is considered a user vimrc)

The user vimrc file often does not exist until created by the user. If you cannot find $HOME/.vimrc (or $HOME/_vimrc on Windows) then you can, and probably should, just create it.

The system vimrc should normally be left unmodified and is located in the $VIM* directory. The system vimrc is not a good place you keep your personal settings. If you modify this file your changes may be overwritten if you ever upgrade Vim. Also, changes here will affect other users on a multi-user system. In most cases, settings in the user vimrc will override settings in the system vimrc.

From :help vimrc:

A file that contains initialization commands is called a "vimrc" file. Each line in a vimrc file is executed as an Ex command line. It is sometimes also referred to as "exrc" file. They are the same type of file, but "exrc" is what Vi always used, "vimrc" is a Vim specific name. Also see |vimrc-intro|.

Places for your personal initializations:

    Unix            $HOME/.vimrc or $HOME/.vim/vimrc
    OS/2            $HOME/.vimrc, $HOME/vimfiles/vimrc
                    or $VIM/.vimrc (or _vimrc)
    MS-Windows      $HOME/_vimrc, $HOME/vimfiles/vimrc
                    or $VIM/_vimrc
    Amiga           s:.vimrc, home:.vimrc, home:vimfiles:vimrc
                    or $VIM/.vimrc

The files are searched in the order specified above and only the first one that is found is read.

(MacOS counts as Unix for the above.)

Note that the mere existence of a user vimrc will change Vim's behavior by turning off the compatible option. From :help compatible-default:

When Vim starts, the 'compatible' option is on. This will be used when Vim starts its initializations. But as soon as a user vimrc file is found, or a vimrc file in the current directory, or the "VIMINIT" environment variable is set, it will be set to 'nocompatible'. This has the side effect of setting or resetting other options (see 'compatible'). But only the options that have not been set or reset will be changed.


* $VIM may not be set in your shell, but is always set inside Vim. If you want to see what it's set to, start up Vim and use the command :echo $VIM


You need to create it. In most installations I've used it hasn't been created by default.

You usually create it as ~/.vimrc.

Tags:

Vim