简体   繁体   中英

Why are Vim filetype options ON when ~/.vimrc is missing but OFF when it is present?

I am using Vim 8.1 on a Ubuntu system. Here are the three cases I have found.

Case 1

$ ls -l ~/.vimrc
ls: cannot access '/home/lone/.vimrc': No such file or directory
$ vim -u NONE +':filetype'
filetype detection:OFF  plugin:OFF  indent:OFF

Case 2

$ ls -l ~/.vimrc
ls: cannot access '/home/lone/.vimrc': No such file or directory
$ vim +':filetype'
filetype detection:ON  plugin:ON  indent:ON

Case 3

$ touch ~/.vimrc
$ ls -l ~/.vimrc
-rw-r--r-- 1 lone lone 0 Nov  2 18:41 /home/lone/.vimrc
$ vim +':filetype'
filetype detection:OFF  plugin:OFF  indent:OFF

Question

  1. Why is it that the filetype options are ON when ~/.vimrc is present but OFF when ~/.vimrc is present?
  2. Where in the Vim :help documentation can I find more about this behavior?
  1. -u NONE disables all vimrc's (including the defaults, more on that below)
  2. With no vimrc, the defaults come in to play (assuming you have vim >7.4.2111 or >8)
  3. With a vimrc, the defaults are not sourced.

From :help defaults.vim :

Defaults without a .vimrc file ~
                            *defaults.vim*
If Vim is started normally and no user vimrc file is found, the
$VIMRUNTIME/defaults.vim script is loaded.  This will set 'compatible' off,
switch on syntax highlighting and a few more things.  See the script for
details.  NOTE: this is done since Vim 8.0, not in Vim 7.4. (it was added in
patch 7.4.2111 to be exact).

This should work well for new Vim users.  If you create your own .vimrc, it is
recommended to add these lines somewhere near the top: >
    unlet! skip_defaults_vim
    source $VIMRUNTIME/defaults.vim
Then Vim works like before you had a .vimrc. Copying $VIMRUNTIME/vimrc_example
is way to do this.  Alternatively, you can copy defaults.vim to your .vimrc
and modify it (but then you won't get updates when it changes).

If you don't like some of the defaults, you can still source defaults.vim and
revert individual settings.  See the defaults.vim file for hints on how to
revert each item.
                        *skip_defaults_vim*
If you use a system-wide vimrc and don't want defaults.vim to change settings,
set the "skip_defaults_vim" variable.  If this was set and you want to load
defaults.vim from your .vimrc, first unlet skip_defaults_vim, as in the
example above.

vim -u NONE starts vim without any config file and sets all options to default values.

vim without ~/.vimrc reads configuration values from a system config file. Try /etc/vim/vimrc or /usr/share/vim/vimrc .

See http://vimdoc.sourceforge.net/htmldoc/starting.html#initialization

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM