I am creating a very simple plugin to make syntax highlighting better in Vim for baan syntax (basically an improved version of syntax/baan.vim).
One file inside ftdetect folder; baan.vim. It looks like this.
au BufRead,BufNewFile *.bc set filetype=baan
The file inside syntax folder; baan.vim. It is almost the same as baan.vim in syntax folder within Vim. With one line of change in syntax highlighting.
My problem is when I open any files with .bc extensions, two more syntax files are called; one before my own plugin syntax file, and other one is after.
bc.vim syntax file is called already from filetyp.vim, I guess. Because filetypes I want to set syntax is with extension .bc. This is the first issue. Second one is that I set filetype to 'baan' but Vim is looking and sourcing all baan.vim files. But once baan.vim is source from myplugin, it is still sourcing the one from Vim itself. How can I solve those issues elegantly without using /after directory?
This is normal. Consider the following.
$VIMRUNTIME/filetype.vim
sources ftdetect/*.vim
scripts near to the end. At this point setf bc
was already executed and the first FileType
event was triggered and processed. BTW. This is the reason why late set ft=baan
works but setf baan
no more. Shouldn't be a problem though, as :syn clear
is executed in $VIMRUNTIME/syntax/synload.vim
automatically. And no, you can't do anything with this unless you patch/replace filetype.vim
.
synload.vim
intentionally sources all matching files (:runtime!
). This is the reason they respect b:current_syntax
variable. The first to set it wins, others step aside by executing :finish
at a top. Nonetheless, they all are sourced and get into :scriptnames
. Note this also means that extending existing syntax with after/syntax
(while not respecting b:current_syntax
) is usually more preferable.