1

我在一个始终将 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一样。还有什么我可以尝试的吗?提前非常感谢。

4

1 回答 1

3

cpp *.cc和文件的默认文件类型*.cpp

文件类型tcl仅为、*.tcl*.tk*.itcl.*.itk*.jacl

我看不出为什么 Vimtcl在加载*.cc文件时会默认为,但您可以检查这些文件是否已安装:

/usr/share/vim/vim7x/ftplugin/cpp.vim
/usr/share/vim/vim7x/indent/cpp.vim
/usr/share/vim/vim7x/syntax/cpp.vim

如果在以下位置进行了正确的检查:

/usr/shhare/vim/vim7x/filetype.vim

你是唯一一个在这台机器上工作的人吗?你使用模型线吗?

于 2012-08-30T13:11:52.653 回答