No syntax highlight on .md files?
Vim properly highlights .markdown
files, but it seems unfamiliar with .md
filetypes.
A comment on at the question https://stackoverflow.com/questions/10964681 seems to imply that .md
is the wrong file extension to use for markdown files. I'm a bit confused.
Is .md
the wrong extension? If not, why isn't Vim highlighting its syntax?
Vim version: 7.4
Analysis
In $VIMRUNTIME/filetype.vim
, you'll find this:
" Markdown
au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,README.md setf markdown
So, only README.md
is detected as Markdown. One reason can be found in the same file when searching for *.md
" Modula 2
au BufNewFile,BufRead *.m2,*.DEF,*.MOD,*.md,*.mi setf modula2
Explanation
Unlike MIME types (where a registry exists), file extensions are not standardized, and (especially for short ones), multiple possible meanings overlap. It's up to you to decide how you want them handled. If it's much more probable that foo.md
means Markdown file than Modula 2 source code, just override Vim's default, e.g. via
au BufNewFile,BufRead *.md setf markdown
in ~/.vim/ftdetect/markdown.vim
, or as described in :help new-filetype
.
The
autocmd BufRead,BufNew *.md setf markdown
didn't work for me on vim 7.4 so I had to use the 'old' traditional way of setting the filetype:
autocmd BufRead,BufNew *.md set filetype=markdown
and this highlights the *.md
files correctly.
Add these lines to your ~/.vimrc
:
augroup markdown
" remove previous autocmds
autocmd!
" set every new or read *.md buffer to use the markdown filetype
autocmd BufRead,BufNew *.md setf markdown
augroup END
Try ending the file with .markdown - it may be long, but that does the trick for me.