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?

  • Did you try to separate set ft=mkd and set ft=mkd.markdown?
    – romainl
    Sep 28, 2015 at 9:46
  • @romainl I don't understand: separate how? Add another set ft line? The file: github.com/plasticboy/vim-markdown/blob/master/ftdetect/… Sep 28, 2015 at 9:48
  • No, both on the same line so that there's an "mkd" event triggered before the "mkd.markdown" event.
    – romainl
    Sep 28, 2015 at 10:18
  • @romainl set ft=mkd || set ft=mkd.markdownin ftdetect seems to work, but when I open a markdown file it echos an empty line and requires me to press enter, not sure why. But that is a bit ugly, specially I'd also have to add a set ft=markdown to make it work for users who update to the new filetype. Sep 28, 2015 at 10:52

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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