3

I want to syntax highlight a header region in custom style and a body region with the existing markdown style:

Title: Test Note Id: 147648d8-8680-4847-8f50-dd4a67f870b5 Created-At: 2018-02-26 22:44:20.784550+00:00 Updated-At: 2018-02-26 22:44:20.784550+00:00 # A heading Some text 

The common start and end of the regions Header and markdownBody is the blank line. I tried this:

syn match HeaderValue contained '.*$' syn match HeaderKey contained '^.*:' nextgroup=HeaderValue syn region Header start="\%^" end="\ze\n\n" transparent contains=HeaderKey unlet! b:current_syntax syn include @MARKDOWN syntax/markdown.vim let b:current_syntax = "mystyle" syn region MarkdownBody start="\n\n" end="\%$" contains=@MARKDOWN hi def link HeaderKey Type hi def link HeaderValue Comment 

This works for the header, but not for the body. If I replace the two occurrences of \n\n with, e. g., END and replace the blank line in the text with END, it works, though.

This seems to mean there is a special handling of \n\n. How can I use a blank line as a start and end marker?

1
  • Thanks to you question, I managed to resolve a similar problem, where I have root region that contains two regions that shares the same element as separator (ie, pascal like function definition where the funtion private vars declaration block and the function body) Commented Oct 28, 2021 at 18:39

1 Answer 1

1

Ok, I found the solution: differently from what I assumed, syn region works line-oriented already, so a single \n instead of \n\n does it. Take a look at the working code if you’re interested.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.