The Computer Oracle

No syntax highlight on .md files?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Melt

--

Chapters
00:00 No Syntax Highlight On .Md Files?
00:31 Answer 1 Score 1
00:40 Answer 2 Score 8
00:54 Accepted Answer Score 12
01:48 Answer 4 Score 9
02:05 Thank you

--

Full question
https://superuser.com/questions/701496/n...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#vim #markdown

#avk47



ACCEPTED ANSWER

Score 12


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.




ANSWER 2

Score 9


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.




ANSWER 3

Score 8


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



ANSWER 4

Score 1


Try ending the file with .markdown - it may be long, but that does the trick for me.