While working a Markdown plugin, we've wanted to change the filetype from mkd to markdown to increase compatibility with other plugins.

To avoid breaking users .vimrc that had autocommands like:

autocmd FileType mkd echo 'a'

we've tried using:

set filetype=mkd.markdown

from ftdetect/markdown.vim, since help 'ft' says both types would be tried.

Now the syntax works fine, but the autocmd does not run. The only way to make it run is to use:

autocmd FileType mkd.markdown echo 'a'

which is obviously bad.

Is there a way to avoid breaking user autocommands in this case?


2 Answers 2



:autocmd FileType *markdown* :echom "a"

This will match for the mk.markdown pattern as well as the regular markdown pattern. It's important to keep the '*' to have the pattern match even when other subtypes have been provided (otherwise markdown would not match the string mkd.markdown, since this is implictly anchored to the start and end and can be seen by using :echo glob2regpat('markdown')


To avoid false positives with a pattern like *markdown*, use * and then filter in the code that you run from the autocmd:

autocmd FileType * call s:CheckMarkdown()

function s:CheckMarkdown()
  if match(&filetype, '\v<markdown>') != -1

  " ... run your desired side-effects

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.