Vim, by default, opens all .md files as "modula2" code. I have never heard of modula2, nor do I plan to use it.

How can I tell vim to always treat foo.md as Markdown (as if I had typed :set ft=markdown)?

  • On what distribution is this the case? I am currently running Archlinux and .md is being seen as markdown – Neikos Feb 4 '15 at 0:25
  • @Neikos This is on Ubuntu 14.04. – Doorknob Feb 4 '15 at 0:30
  • on fedora as well I correctly get markdown syntax on .md files – guido Feb 4 '15 at 0:33
  • 2
    This has already been answered on SO. You may find more and different information there. – bsmith89 Feb 4 '15 at 0:43
  • 3
    FYI, as of Vim 7.4.480, *.md files are recognized as Markdown instead of modula2 by default. – fwalch Feb 5 '15 at 20:49

In the file filetype.vim that is shipped with your distribution you will find a line that looks probably similar to this (on my machine it lives at /usr/share/vim/vim74) :

au BufNewFile,BufRead *.md,*.m2,*.mi setf modula2

Now, this tells vim to set the filetype as modula2 if your file has such an ending.

To override this behaviour you can put a line like this in your own .vimrc (Taken from the Archlinux filetype.vim) :

au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,*.mdwn,*.md  set ft=markdown


I previously had setf as the function to be called, but it seems to be a reserved function for the filetype.vim file.


I currently have this line as an ugly hack in my .vimrc:

autocmd BufRead *.md set ft=markdown

I'm still wondering if there's a better way, though.

  • 1
    this does not work in fedora, it seems the /usr/share/vim/vim74/filetype.vim definitions will override this setting – guido Feb 4 '15 at 1:01
  • @guido, I wonder if that depends on when you enable filetype detection? If you add that autocmd after filetype on (with or without the plugin / indent flags), I would guess the results are better. Not tested, just speculation. – tommcdo Feb 6 '15 at 15:00

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.