Difference between vim plugins & packages
:help plugin tells us
Vim's functionality can be extended by adding plugins. A plugin is nothing
more than a Vim script file that is loaded automatically when Vim starts. You
can add a plugin very easily by dropping it in your plugin directory.
:help packages gives
A Vim package is a directory that contains one or more plugins. The
advantages over normal plugins:
- A package can be downloaded as an archive and unpacked in its own directory.
Thus the files are not mixed with files of other plugins. That makes it
easy to update and remove.
- A package can be a git, mercurial, etc. repository. That makes it really
easy to update.
So vim calls 'plugins' single script files that execute commands. 'Packages', on the other hand, contain one or more plugins. Unfortunately, vim doesn't distinguish here where perhaps it should.
The plugins you and I are familiar with are the GitHub repos and vim.org compressed directories where the structure matches that of the runtime path:
This is a list of directories which will be searched for runtime
filetype.vim filetypes by file name |new-filetype|
scripts.vim filetypes by file contents |new-filetype-scripts|
autoload/ automatically loaded scripts |autoload-functions|
colors/ color scheme files |:colorscheme|
compiler/ compiler files |:compiler|
doc/ documentation |write-local-help|
ftplugin/ filetype plugins |write-filetype-plugin|
indent/ indent scripts |indent-expression|
keymap/ key mapping files |mbyte-keymap|
lang/ menu translations |:menutrans|
menu.vim GUI menus |menu.vim|
pack/ packages |:packadd|
plugin/ plugin scripts |write-plugin|
print/ files for printing |postscript-print-encoding|
spell/ spell checking files |spell|
syntax/ syntax files |mysyntaxfile|
tutor/ files for vimtutor |tutor|
That is, what you and I conceive of as plugins are really mini-runtime directories. But, we just said a plugin is a single script?!
Well, no. A
plugin script lives in
&rtp/plugin and is just executed. A plugin in the more usual sense is a collection of scripts organized into this mini-runtime directory.
And each of those directories can live in a package. See my dotfiles for some examples of package organization.
What do I do?
Your question deals specifically with a (new) filetype and its accompanying syntax files. But, to play nicely in the vim plugin ecosystem, you still want to mimic the
ftdetect can hold vimscript to detect the filetype, as below; and
syntax can hold vimscript to define the syntax for the filetype
So you might have the following files
au BufNewFile,BufRead *.foo set filetype=foo
echom "Our syntax highlighting code will go here."
let b:current_syntax = "foo"
" do something useful
myplugin can then be a git repo (or similar) that is "installed" to
- Learn Vimscript the Hardway from Steve Losh contains a much deeper introduction to this material than I can present here.