Where is my .vimrc file?

I have been using Vim, and I would really like to save my settings. The problem I am having is that I cannot find my .vimrc file, and it is not in the standard /home/user/.vimrc location. How might I find this file?


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

You usually create it as ~/.vimrc .


: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.


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

    链接地址: http://www.djcxy.com/p/28630.html

    上一篇: 在文本模式下在Emacs中设置4个空格缩进

    下一篇: 我的.vimrc文件在哪里?