尝试在.vimrc 中设置syntax enable 而不是syntax on。
直接来自:h syntax
This command switches on syntax highlighting: >
:syntax enable
What this command actually does is to execute the command >
:source $VIMRUNTIME/syntax/syntax.vim
If the VIM environment variable is not set, Vim will try to find
the path in another way (see |$VIMRUNTIME|). Usually this works just
fine. If it doesn't, try setting the VIM environment variable to the
directory where the Vim stuff is located. For example, if your syntax files
are in the "/usr/vim/vim50/syntax" directory, set $VIMRUNTIME to
"/usr/vim/vim50". You must do this in the shell, before starting Vim.
*:syn-on* *:syntax-on*
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
阅读Here了解更多信息。
编辑:经过更多研究,我发现如果上述方法不起作用,那是因为该特定文件类型的文件类型插件正在覆盖用户设置。为了解决这个问题,您可以在您的主 vim 文件夹中创建一个名为 after 的新文件夹。 after 中的每个文件都源自/usr/share/vim74 中的任何文件。 after的结构必须与vim74文件夹文件夹的结构相匹配。
为了让事情更简单,我写了一个快速脚本
#!/usr/bin/bash
# Make the after folders you need
mkdir -p $HOME/.vim/after/ftplugin
# Create the Global Settings file for syntax highlighting and formatting options
touch $HOME/.vim/after/fo_globals.vim
# Create links to the fo_globals file
for file in /usr/share/vim/vim74/ftplugin/*.vim
do
ln -s $HOME/.vim/after/fo_globals.vim $HOME/.vim/after/ftplugin/`basename $file`
done
然后用语法和格式选项填写您的全局文件。我的看起来像这样。
syntax enable
set formatoptions-=c
set formatoptions-=r
set formatoptions-=o
set autoindent
set smartindent
set nocindent
set backspace=indent,eol,start
set expandtab
set tabstop=4
set shiftwidth=4
set shiftround