3

When writing Markdown, fenced code written between triple backticks is highlighted, but not code in indented blocks (I don't care about language specific highlighting). How can I get vim to recognize indented blocks and highlight them as code? Using nvim v0.4.3 with syntastic and vim-syntax-extra.

4
  • FYI syntastic is for syntax checking, not syntax highlighting.
    – lcd047
    Feb 2, 2022 at 5:02
  • 1
    vim -u DEFAULTS -U NONE, run :syntax enable, :hi link markdownCodeBlock Debug, I some code, and the indented block is highlighted…
    – D. Ben Knoble
    Feb 2, 2022 at 14:52
  • @D.BenKnoble can you write this as an answer? do you know why this isn't enabled by default?
    – qwr
    Feb 2, 2022 at 15:15
  • Depends on the colorscheme, mostly. The default syntax file just doesn’t link these groups.
    – D. Ben Knoble
    Feb 2, 2022 at 15:28

2 Answers 2

3

The default syntax file for markdown doesn’t link the code or code block groups, but:

highlight link markdownCode somegroup
highlight link markdownCodeBlock somegroup

Will do just fine

1
1

I tested plugins https://github.com/gabrielelana/vim-markdown and https://github.com/preservim/vim-markdown which both support indented code blocks correctly (though for some reason coloring the code differently, and what stood out to me initially is that perservim's plugin folds headers by default and gabrielelana's plugin spellchecks by default).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.