Skip to content

Instantly share code, notes, and snippets.

@jrwrigh
Created January 20, 2020 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrwrigh/970e2e107965945e0888f3bb3dffd608 to your computer and use it in GitHub Desktop.
Save jrwrigh/970e2e107965945e0888f3bb3dffd608 to your computer and use it in GitHub Desktop.
Vim syntax file to Hugo markdown files
" Vim syntax file
" Language: markdown with embedded yaml, toml for Hugo
" Author: James Wright (james@jameswright.xyz)
" License: MIT
" Inspired by https://github.com/pbrisbin/vim-syntax-shakespeare/blob/master/after/syntax/haskell.vim
" store and remove current syntax value
if exists('b:current_syntax')
let old_syntax = b:current_syntax
unlet b:current_syntax
endif
syn include @yaml syntax/yaml.vim
unlet b:current_syntax
syn include @toml syntax/toml.vim
unlet b:current_syntax
if getline(1) =~ '---'
syn region yamlBlock matchgroup=quasiQuote start=/\%^---/ end=/^---/ contains=@yaml
elseif getline(1) =~ '+++'
syn region tomlBlock matchgroup=quasiQuote start=/\%^+++/ end=/^+++/ contains=@toml
endif
if version < 508
command! -nargs=+ HiLink hi link <args>
else
command! -nargs=+ HiLink hi def link <args>
endif
HiLink quasiQuote Boolean
delcommand HiLink
" restore current syntax value
if exists('old_syntax')
let b:current_syntax = old_syntax
endif
@jrwrigh
Copy link
Author

jrwrigh commented Jan 20, 2020

What's this?

This will allow for the front matter of a Hugo markdown document to be syntax highlighted differently than the markdown itself.

image
Here you can see that both the yaml front matter and the markdown body is syntax highlighted correctly

How do I use it?

Put this file in [vim/nvim config path]/after/syntax/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment