我在一個系統(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