vim - 为什么当 ~/.vimrc 丢失时 Vim 文件类型选项打开但存在时关闭?
问题描述
我在 Ubuntu 系统上使用 Vim 8.1。这是我发现的三个案例。
情况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
案例2
$ ls -l ~/.vimrc
ls: cannot access '/home/lone/.vimrc': No such file or directory
$ vim +':filetype'
filetype detection:ON plugin:ON indent:ON
案例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
问题
- 为什么
filetype
选项在存在时~/.vimrc
为ON,但在存在时为OFF~/.vimrc
? - 在 Vim
:help
文档的哪里可以找到有关此行为的更多信息?
解决方案
-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.
推荐阅读
- java - 模拟方法实现 Junit mockito
- c++ - 分布的地雷的最大值和最小值之间的最小差值
- python - cv2.imencode 是如何工作的?输出两个相同形状的图像的不同形状
- php - 通过 php curl 将文件上传到 HDFS
- python - 在 anaconda 中更新 Spyder 后出现内核错误
- linux - Linux Bash If else 在 while 循环中
- apache-kafka - 通过 HDFS 接收器连接器将 Debezium Kafka 主题数据写入 Hive 不起作用
- javascript - 如何在android studio Webview中阻止网页广告?
- ruby-on-rails - Rails omniauth-google-oauth2 图像大小不适用
- ruby-on-rails - docker上的Rails:Mysql2 :: Error :: ConnectionError:未知的MySQL服务器主机'db'