DervishD wrote:
Hi all :)
I would like to have configuration data, syntax rules and indent
functions for a filetype together in just one file because this way is
much more easy to maintain for me (long story). Apart from the obvious
disadvantage that having all together in a file makes impossible to
deactivate only syntax, only plugin and only indent for that given
filetype (it becomes an "all or nothing" thing), is there any problem in
not having the files in three separate directories? In fact, is there
any problem in having ALL that data in the corresponding ftplugin?
I'm just curious...
Raúl Núñez de Arenas Coronado
The scripts in the indent/ syntax/ and ftplugin/ subdirectories of the
directories in 'runtimepath' are not run at the same time, therefore it is
logical to keep them separate:
ftplugin/<filetype>.vim is sourced at the FileType autocommand event for
<filetype>. If filetype detection isn't ON, or if filetype plugins aren't
enabled (":filetype plugin on" hasn't been issued), it is not sourced at all.
syntax/<syntaxname>.vim is sourced at the Syntax autocommand event for
<syntaxname>. If syntax highlighting is not enabled (":syntax on" hasn't been
issued), it is not sourced at all. If filetype detection is off (":filetype
on" hasn't been issued), then, even if syntax highlighting is enabled, it is
sourced only when 'syntax' is set explicitly (e.g. by hand).
indent/<filetype>.vim is sourced at (IIUC) the FileType event for <filetype>,
but only if filetype-related indenting has been enabled (":filetype indent on"
has been issued).
Now what should these files contain?
ftplugin/<filetype>.vim contains chiefly ":setlocal" and/or ":map <buffer>"
statements specific to files of the given filetype.
syntax/<syntaxname>.vim contains ":syntax" and possibly ":highlight default"
statements to define how to colour the text in files with the given syntax.
indent/<filetype>.vim contains statements to define how to indent the data in
the file: usually either
setlocal cindent
setlocal cinoptions=<something>
or
setlocal indentexpr=<something>
and possibly a function to be called by the indenting expression.
If you want to keep everything together, you can set autocommands for the
Filetype and Syntax events in your vimrc, but as "what you want to do" becomes
more involved, you'll find that your vimrc becomes more and more cluttered and
that you need to put things into different files just to keep order. Been
there done that.
Notice the use of ":setlocal" and ":map <buffer>" to avoid clobbering settings
for other files, and ":highlight default" to avoid errors if a colour scheme
has been set.
Best regards,
Tony.