我在一个系统(linux)上始终将cpp文件(* .cc)识别为tcl
文件。我不知道是什么文件类型,但我想覆盖它。如果手动执行:set ft=cpp
,则会选择正确的语法高亮显示。但是,我遇到麻烦,自动设置,我不想使用modeline
选项。我自己的.vimrc
不会干涉(如果我重命名它,结果相同)。如果vim仍然选择错误的语法荧光笔,该怎么办?
从
*ftplugin-overrule*
If a global filetype plugin does not do exactly what you want, there are three
ways to change this:
1. Add a few settings.
You must create a new filetype plugin in a directory early in
'runtimepath'. For Unix, for example you could use this file:
vim ~/.vim/ftplugin/fortran.vim
You can set those settings and mappings that you would like to add. Note
that the global plugin will be loaded after this, it may overrule the
settings that you do here. If this is the case, you need to use one of the
following two methods.
我以前使用此选项在另一台机器上,并且工作的VIM帮助(:help ftplugin-override
)。我试过
<file> .vim/ftplugin/tcl.vim
set filetype=cpp
"au BufRead,BufNewFile * set filetype=cpp
第一行设置正确的filetype
(:set ft?
回报CPP),但语法高亮不一样,如果我说:set ft=cpp
。它仍然是tcl
语法突出显示。第二行什么都不做。
2. Make a copy of the plugin and change it.
You must put the copy in a directory early in 'runtimepath'. For Unix, for
example, you could do this:
cp $VIMRUNTIME/ftplugin/fortran.vim ~/.vim/ftplugin/fortran.vim
Then you can edit the copied file to your liking. Since the b:did_ftplugin
variable will be set, the global plugin will not be loaded.
A disadvantage of this method is that when the distributed plugin gets
improved, you will have to copy and modify it again.
似乎有在我$VIMRUNTIME
目录/usr/share/vim/vim72/ftplugin/
称为tcl.vim
没有文件。
3. Overrule the settings after loading the global plugin.
You must create a new filetype plugin in a directory from the end of
'runtimepath'. For Unix, for example, you could use this file:
vim ~/.vim/after/ftplugin/fortran.vim
In this file you can change just those settings that you want to change.
与1具有相同的效果还有什么我可以尝试吗?提前致谢。
该死的,有一个模式,我没看到!我的同事为什么这么做?谢谢罗曼! – Sebastian
中线模式很有用,但您的团队必须对某些东西进行标准化。 – romainl