I am using Vim 8.2 on Windows 10.
I have a custom compiler plugin called msbuild which I use to build a single C++ file. Each time I work on a new file, I must type:
:compiler msbuild
to make sure my msbuild compiler plugin is loaded, otherwise make fails. It's very annoying. I can type:
:compiler! msbuild
to set it globally, but then it is set for all files, even non C++ ones. I'd like my msbuild compiler plugin to be automatically loaded when I start working a new C++ file (extension :.cpp). I have tried using autocmd with FileType with no success:
autocmd FileType cpp compiler msbuild
I did not find a working example using Google. How can I achieve this?
Your autocommand probably fails because you didn't enable filetype detection and/or filetype plugins. Adding the following line to your
vimrcshould get you out of trouble:If you also want filetype-specific indenting (you probably should) you can use this line instead:
If, somehow, you don't want to enable filetype detection, you can condition your autocommand on the file extension:
That said, the most canonical way to deal with the problem at hand, which is what @phd hinted at, is to…
Enable filetype detection, plugins, and indenting in your
vimrcwith:Create a custom ftplugin:
With the following content: