How do I get good vim syntax highlighting on a .md file?
By default vim doesn't recognize .md
files, but it does recognize .markdown
.
To make vim recognize .md
, add this line to your ~/.vimrc
au BufNewFile,BufFilePre,BufRead *.md set filetype=markdown
If you want to dog deeper, you can read through the vim file for parsing markdown .
:e $VIMRUNTIME/syntax/markdown.vim
It shows how markdown semantic categories are mapped to highlighting groups
hi def link markdownH1 htmlH1
hi def link markdownH2 htmlH2
hi def link markdownH3 htmlH3
hi def link markdownH4 htmlH4
hi def link markdownH5 htmlH5
hi def link markdownH6 htmlH6
hi def link markdownHeadingRule markdownRule
hi def link markdownH1Delimiter markdownHeadingDelimiter
hi def link markdownH2Delimiter markdownHeadingDelimiter
hi def link markdownH3Delimiter markdownHeadingDelimiter
hi def link markdownH4Delimiter markdownHeadingDelimiter
hi def link markdownH5Delimiter markdownHeadingDelimiter
hi def link markdownH6Delimiter markdownHeadingDelimiter
hi def link markdownHeadingDelimiter Delimiter
hi def link markdownOrderedListMarker markdownListMarker
hi def link markdownListMarker htmlTagName
hi def link markdownBlockquote Comment
hi def link markdownRule PreProc
hi def link markdownFootnote Typedef
hi def link markdownFootnoteDefinition Typedef
hi def link markdownLinkText htmlLink
hi def link markdownIdDeclaration Typedef
hi def link markdownId Type
hi def link markdownAutomaticLink markdownUrl
hi def link markdownUrl Float
hi def link markdownUrlTitle String
hi def link markdownIdDelimiter markdownLinkDelimiter
hi def link markdownUrlDelimiter htmlTag
hi def link markdownUrlTitleDelimiter Delimiter
hi def link markdownItalic htmlItalic
hi def link markdownItalicDelimiter markdownItalic
hi def link markdownBold htmlBold
hi def link markdownBoldDelimiter markdownBold
hi def link markdownBoldItalic htmlBoldItalic
hi def link markdownBoldItalicDelimiter markdownBoldItalic
hi def link markdownCodeDelimiter Delimiter
hi def link markdownEscape Special
hi def link markdownError Error
The vim documentation
on syntax lists some common system colors
Red LightRed DarkRed
Green LightGreen DarkGreen SeaGreen
Blue LightBlue DarkBlue SlateBlue
Cyan LightCyan DarkCyan
Magenta LightMagenta DarkMagenta
Yellow LightYellow Brown DarkYellow
Gray LightGray DarkGray
Black White
Orange Purple Violet
Most of these worked on my system (Ubuntu 20.04), but not all.
To ~/.vimrc
add lines to change syntax highlighting based on semantic category.
cterm
(color terminal format) can be none
or bold
or italic
or bold, italic
ctermfg
(color terminal foreground) is the color of the text itself.
ctermbg
(color terminal backgroun) is the highlighting color.
gui
, guifg
, guibg
are the corresponding values for gui mode, but I never use this.
Here are some values I like.
highlight ColorColumn ctermbg=16
highlight Delimiter ctermfg=DarkGray
highlight htmlH1 cterm=bold ctermfg=Blue
highlight htmlH2 cterm=bold ctermfg=Blue
highlight htmlH3 cterm=bold ctermfg=Blue
highlight htmlH4 cterm=bold ctermfg=Blue
highlight markdownCode cterm=none ctermfg=DarkCyan
highlight markdownCodeBlock cterm=none ctermfg=DarkCyan