I’m after a means by which I can add additional commands to a text file via vim. For example, just as you can do something like this:
# vim:syntax=foo
I’d like to do something like:
# vim:option call matchadd('Special', '\(REQUIRED\|OPTIONAL\)')
Any ideas? I know I can write a syntax file, but this is not what I’m after for now.
Vim modeline syntax (see
:help modeline) is not intended to specify commandsto execute during file opening. That is exactly what autocommands is for (see
:help autocommand). What you are trying to do should be an autocommandsimilar the following.
or
(Here instead of
*.fooyou can use any pattern that matches path or filename(or both) of the target file.)
If the configuration you are setting up is local to some files or a project,
and you don’t want to pollute your
.vimrcwith thoseautocmds, uselocalvimrc plugin. It allows you to have a “local”
.vimrcfile next toyour target file or project folder. Script stored in that
.lvimrcisexecuted when you open files in the same directory where the “local”
.vimrcis, or in its subdirectories. Autocommands shown above (or any other
configurations) can be stored in a
.lvimrcfile local the project. Fordetails about localvimrc configuration see the homepage of the plugin.