2

I have a syntax I'm trying do make. It's yaml embedded in markdown for use with Hugo. The yaml region is enclosed by --- and this must be at the top of the file.

---
[yaml front matter stuff]
.
.
.
---
# Here starts the markdown

I've defined a region that specifies where the yaml region should start: syn region yamlBlock matchgroup=quasiQuote start=/^---/ end=/^---/ contains=@yaml (inspired by this embedded haskell syntax file)

I want this region to only apply if it is at the very top of the file.

I've tried adding an if statement:

if getline(1) =~ '---'
    syn region yamlBlock matchgroup=quasiQuote start=/^---/ end=/^---/ contains=@yaml
endif

But this will only update when the buffer is reloaded. ie. If I have it open and add a blank line at the top of the file, the code inside

---
[....]
---

will still be highlighted as yaml.

4

Try tweaking your region start pattern to match the start of the file:

start=/\%^---/

See :help start-of-file.

|improve this answer|||||

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.