我在一个始终将 cpp 文件 (*.cc) 识别为tcl
文件的系统 (linux) 上。我不知道那是什么文件类型,但我想覆盖它。如果我手动选择正确的语法突出显示:set ft=cpp
。但是,我在自动设置时遇到了麻烦,我不想使用该modeline
选项。我自己的.vimrc
不会干扰(如果我重命名它,结果相同)。
来自 vim 帮助 ( :help ftplugin-override
)
*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.
我之前在另一台机器上使用过这个选项,并且有效。我试过了
<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一样。还有什么我可以尝试的吗?提前非常感谢。