在我的 .vimrc 文件中,我使用:
syntax on
今天,我仔细阅读了其他开发人员的一些 .vimrc 文件,我注意到一些使用:
syntax enabled
有区别吗?这两者是否只是使用不同的位置来实现相同的目标?
最佳答案
Vim 声称什么
对于 syntax on
对比 syntax enable
,帮助文件声称:
The ":syntax enable" command will keep your current color settings. This
allows using ":highlight" commands to set your preferred colors before or
after using this command. If you want Vim to overrule your settings with the
defaults, use: >
:syntax on
我无法验证这些声明
我在 Vim 中看到的行为似乎与上述帮助语句不符。
在本地测试一些空后
.vimrc
s 并尝试使用 on
, enable
,以及高亮命令的放置,我无法弄清楚 Vim 实际上在做什么(我用 highlight ColorColumn guibg=#331111
和 set colorcolumn=80
进行了测试)。突出显示有时会被覆盖,有时不会。只让 Vim 设置一次语法
我不再信任 Vim,所以我只让语法设置一次,永远。这是我的
.vimrc
中的内容:if !exists("g:syntax_on")
syntax enable
endif
我用
enable
因为上面声称它不会覆盖您的设置,但是在启动 Vim 时它似乎没有任何区别。更多细节
你可以看到
h g:syntax_on
显示 on
和 enable
源相同的文件:Details:
The ":syntax" commands are implemented by sourcing a file. To see exactly how
this works, look in the file:
command file ~
:syntax enable $VIMRUNTIME/syntax/syntax.vim
:syntax on $VIMRUNTIME/syntax/syntax.vim
如果你好奇,
g:syntax_on
设置在 $VIMRUNTIME/syntax/synload.vim
同样在没有插件/设置的情况下运行 Vim
vim -u NONE
不加载任何语法文件。
关于vim - vimscript 中的 `syntax on` 和 `syntax enable` 有区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33380451/