4

I often "pre-compose" and save my longer questions for StackExchange usign Vim / GVim.

Does a syntax highlighting file for the StackExchange markdown already exist? If yes, where can I obtain it?

Googling for vim syntax file stackexchange leads to general questions / answers on various SE-sites about "vimish" syntax highlighting in general.

0
4

AFAIK no.

But Vim already supports Markdown out of the box and there are probably a few alternative syntax scripts available if the default doesn't satisfy you.

0

Here is what I maid to implement most Stackexchange syntax features :
Feel free to use or improve it.

" see : https://stackoverflow.com/editing-help
" for stack(exchange|overflow) syntax explaination

" Uncomment next line if you want <br> to create new lines
" when this syntax file is loaded :
" :%s/\(<br\/\?>\)\(.\)/\1\r\2/g

" Uncomment next lines if you want <br> to create new line
" while writing it in insert mode :
" :inoremap <lt>br> <lt>br><c-m>
" :inoremap <lt>br/> <lt>br/><c-m>

sy clear
sy match SOTitle "^#\+.*$"
sy match SOTitle "^.*\n\(=\+\|-\+\)$"
sy match SORule "^\n---\+\n$"
sy match SOCode "^\(    \| *\t\| >\)[ \t]*[^- ].*$"
sy match SOTag  " \[[^\]]*\] "
sy match SOLink " !\?\[[^]]*\]([^)]*)"
sy match SOLink " \[[^]]*\]\[[^]]*\]"
sy match SONewLine "<br/\?>"
sy match SOHTML "<[^>]*/\?>"
sy match SOURL  "<http[^ >]*>"

sy match SOIgnore "`\+"  contained
sy match SOIgnore "\*\+" contained
sy match SOIgnore "_\+"  contained

"Uncomment next lines if you want simpler bold/italic, with no hidden.
"sy match SOItalic " \*[^*]*\*"
"sy match SOItalic " _[^*]*_"
"sy match SOBold " \*\*[^*]*\*\*"
"sy match SOBold " __[^*]*__"
"sy match SOBoldItalic " \*\*\*[^*]*\*\*\*"
"sy match SOBoldItalic " ___[^*]*___"

sy region SOItalic matchgroup=SOIgnore start="_"  end="_"
sy region SOItalic matchgroup=SOIgnore start="\*" end="\*"
sy region SOBold   matchgroup=SOIgnore start="__"   end="__"
sy region SOBold   matchgroup=SOIgnore start="\*\*" end="\*\*"
sy region SOBoldItalic matchgroup=SOIgnore start="___"    end="___"
sy region SOBoldItalic matchgroup=SOIgnore start="\*\*\*" end="\*\*\*"

sy region SOBackstick matchgroup=SOIgnore start="`"   end="`"
sy region SOCode      matchgroup=SOIgnore start="```" end="```"

hi! link SOTitle Title
"hi! link SOIgnore Ignore
hi! link SOTag SpecialKey
hi! link SOLink Number
hi! link SONewLine Special
hi! link SOHTML Special
hi! link SOURL Number
hi! link SOBackstick Statement

hi! SORule cterm=bold ctermbg=196
hi! SOCode cterm=bold ctermbg=17
"hi! SOBackstick cterm=bold ctermfg=11 ctermbg=233
hi! SOBold cterm=bold
hi! SOItalic cterm=italic ctermfg=120
hi! SOBoldItalic cterm=bold,italic ctermfg=120
hi! SOIgnore ctermfg=242 ctermbg=0

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.