Is it possible to use a variable as the subject of an autocmd
?
I want to allow plugin users to define a list of FileTypes
the plugin will operate on.
This requires that I set an autocommand
for each of the given FileTypes
.
The below code doesn't work:
let g:enabledFileTypes = ['javascript', 'vim']
autocmd FileType g:enabledFileTypes * call myFunction()
This does:
autocmd FileType javascript,vim * call myFunction()
Is it possible to declare an autocommand that uses a variable as the file type list?
The *
glob is useless in a FileType
autocommand.
You can join()
that list into a comma-separated string:
execute "autocmd FileType " . join(g:enabledFileTypes, ",") . " call myFunction()"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With