vim - vimscript 中的 `syntax on` 和 `syntax enable` 有区别吗?

标签 vim

在我的 .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=#331111set colorcolumn=80 进行了测试)。突出显示有时会被覆盖,有时不会。

只让 Vim 设置一次语法

我不再信任 Vim,所以我只让语法设置一次,永远。这是我的 .vimrc 中的内容:
if !exists("g:syntax_on")
    syntax enable
endif

我用 enable因为上面声称它不会覆盖您的设置,但是在启动 Vim 时它似乎没有任何区别。

更多细节

你可以看到 h g:syntax_on显示 onenable源相同的文件:
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/

相关文章:

vim - 选择文本并使用键盘映射保存

vim - 在 vim 中重新排列制表符分隔文本文件中的列的最佳方法是什么?

macos - 这是适用于 OS X Snow Leopard 的 Vim 版本吗?

regex - 如何使用 Vim 或 Perl 在文件中的特定行上方插入一行?

python - 如何修复 Vim 中对象实例上缺少 Python 自动完成?

vim - 自定义绑定(bind)将选择内容括在括号中

sorting - 如何在 Vim 中根据标题对段落进行排序?

c++ - 如何让 YouCompleteMe 突出显示错误和警告?

vim - 使用vim-fzf忽略node_modules

linux - 使用 vim,什么是 "' < ,'>"?