Not everyone considers setting
b:undo_ftpluginto be a "best practice" the way I do, but as far as I can tell, the behavior described in this question depends on it being set as part of the autocommand. This isn't an unreasonable thing to do, particularly if one religiously sets it, like I do.
I've been working on a plugin (call it
foo) that uses multiple filetypes to
enhance the editing experience of files in a particular path while still
leveraging all the goodies that are setup by their respective filetype plugins.
More concretely, the plugin sets the filetype of any file in this path to
foo.original_filetype. Vim's filetype plugin mechanism will use filetype
plugins (and filetype autocommands) for both the
filetypes in this case:
When a dot appears in the value then this separates two filetype names.
/* vim: set filetype=c.doxygen : */
This will use the "c" filetype first, then the "doxygen" filetype. This works both for filetype plugins and for syntax files. More than one dot may appear.
Now, I ran into a bizarre situation while experimenting with this plugin. For
reasons™, I was keeping some extra
foo filetype settings separate from my
usual config, so I had done something like this:
" in a personal file sourced at the top of my vimrc augroup FooStuff autocmd! autocmd FileType *foo* nnoremap <buffer> f :echo "foo!"<CR> autocmd FileType *foo* let b:undo_ftplugin = 'nunmap <buffer> f' augroup END
*foo* is necessary, since the entire dotted-filetype is matched
Now, if I enter vim and
:set filetype=foo.markdown, and then
n \u3 *@:call UnderlineHeading(3)<CR> n \u2 *@:call UnderlineHeading(2)<CR> n \u1 *@:call UnderlineHeading(1)<CR> n \o *@:silent !open %<CR>:redraw!<CR> o i#3 *@:<C-U>execute "normal! ?^###\\s.?e\r\rvg_"<CR> o i#2 *@:<C-U>execute "normal! ?^##\\s.?e\r\rvg_"<CR> o i#1 *@:<C-U>execute "normal! ?^#\\s.?e\r\rvg_"<CR> o ih- *@:<C-U>execute "normal! ?^--\\+$\r\rkvg_"<CR> o ih= *@:<C-U>execute "normal! ?^==\\+$\r\rkvg_"<CR>
Those are all markdown mappings, and
f is conspicuously absent. What gives?