为什么 Vim 文件类型选项在缺少 ~/.vimrc 时打开,但在存在时关闭?
Why are Vim filetype options ON when ~/.vimrc is missing but OFF when it is present?
我在 Ubuntu 系统上使用 Vim 8.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
案例二
$ ls -l ~/.vimrc
ls: cannot access '/home/lone/.vimrc': No such file or directory
$ vim +':filetype'
filetype detection:ON plugin:ON indent:ON
案例三
$ 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
问题
- 为什么
filetype
选项在出现 ~/.vimrc
时打开,但在出现 ~/.vimrc
时关闭?
- 我可以在 Vim
:help
文档的哪个位置找到有关此行为的更多信息?
vim -u NONE
在没有 任何 配置文件的情况下启动 vim
并将所有选项设置为默认值。
vim
没有 ~/.vimrc
从系统配置文件中读取配置值。试试 /etc/vim/vimrc
或 /usr/share/vim/vimrc
.
见http://vimdoc.sourceforge.net/htmldoc/starting.html#initialization
-u NONE
禁用所有 vimrc(包括默认值,更多内容见下文)
- 没有 vimrc,默认值开始播放(假设你有 vim >7.4.2111 或 >8)
- 使用 vimrc,不获取默认值。
来自: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.
我在 Ubuntu 系统上使用 Vim 8.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
案例二
$ ls -l ~/.vimrc
ls: cannot access '/home/lone/.vimrc': No such file or directory
$ vim +':filetype'
filetype detection:ON plugin:ON indent:ON
案例三
$ 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
问题
- 为什么
filetype
选项在出现~/.vimrc
时打开,但在出现~/.vimrc
时关闭? - 我可以在 Vim
:help
文档的哪个位置找到有关此行为的更多信息?
vim -u NONE
在没有 任何 配置文件的情况下启动 vim
并将所有选项设置为默认值。
vim
没有 ~/.vimrc
从系统配置文件中读取配置值。试试 /etc/vim/vimrc
或 /usr/share/vim/vimrc
.
见http://vimdoc.sourceforge.net/htmldoc/starting.html#initialization
-u NONE
禁用所有 vimrc(包括默认值,更多内容见下文)- 没有 vimrc,默认值开始播放(假设你有 vim >7.4.2111 或 >8)
- 使用 vimrc,不获取默认值。
来自: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.