Highlight syntax inside Markdown
Modern versions of Vim include support for syntax highlighting and filetype handling of Markdown files. Tim Pope maintains this functionality in his vim-markdown repo but this isn’t a plugin that needs to be installed. Vim includes this syntax file in its source distribution. So this is functionality you already have, and functionality that is essential if you’re using Vim to take notes in Markdown format.
But you may not realize that Vim is able to highlight the syntax of fenced code blocks. Fenced code blocks are code snippets you embed in Markdown with triple backticks. Markdown supports a language identifier after the backticks which will indicate to editors and renderers how to highlight the syntax inside the block. For example:
```ruby
def full_name
"#{first_name} #{last_name}"
end
```
Vim can properly highlight this syntax, but this functionality is not enabled by default. To enable it, you need to specify which languages you wish to support. Put something like this in your .vimrc
:
let g:markdown_fenced_languages = ['html', 'python', 'ruby', 'vim']
But feel free to specify any and all languages you regularly embed in Markdown documents. In the demo below, you can see various languages I have listed in my config. When I add vim
to the start of the fenced block, Vim instantly highlights the code as VimL.