Explaining the steps you can use to troubleshoot such issues.
First, you can use a command such as
:au BufRead *.mm to inspect which autocmds exist for that particular extension. You can use that to double check that your configuration actually took effect. (Which it did in your case.)
Second, you can use command
:verbose set ft? to inspect the filetype for the current buffer and see where Vim got that filetype setting from.
In your case, I expect this showed that it was coming from a view created by
mkview, so that would explain why your setting wasn't taking effect. Well, actually your setting was taking effect but the filetype was later being overwritten by the view being restored.
If you want to keep using views (for example, for manual folds and cursor position), but you still want your filetype (and potentially other local settings, such as shiftwidth, soft tabs, expand tabs, etc.) to be reconfigured every time you reopen the file (to reflect changes in your configuration), you can set
'viewoptions' to configure what is saved in your views.
set viewoptions-=options will
For example, to prevent Vim from saving local options, including the filetype, you can use:
That way Vim won't save any local settings (filetype included) in the saved views. Of course, this will only take effect the next time you save a view. Views that are already saved will have that information preserved and it will be loaded automatically.
You might also want to take a look at this
dist#ft#FTmm() function that Vim runtime uses by default for files with the
If you look at that code, you'll see it will read the first 20 lines of the file and try to find a line starting with either
@import. If any of these is found on the first 20 lines, Vim will set the filetype to
objcpp (Objective C++), which I imagine might be what you wanted?
It only falls back to
nroff if it can't detect the Objective C++ reliably, which it does looking at those 20 first lines of the file.
So maybe ensuring your file will have includes or imports on the first few lines would be enough to have this working out-of-the-box with the most appropriate filetype without the need for any extra configuration?