tags:

views:

42

answers:

2

I often edit markdown files with in-line code examples. these all start with the line “~~~ {.cpp}” (for C++). Is there an easy way to highlight everything between the line “~~~ {.cpp}” and the line “~~~” with C++ syntax hightlighting?

(Or even better, make it use “x highlighting” after “~~~ {.x}”.)

A: 

Add the following to your syntax file for that file type, or just to your .vimrc

syn region myComment start="~~~" end="~~~" contained
hi def link myComment          Comment

This will tell vim to highlight those regions as comments.

sleepynate
while that makes sense, it doesn't seem to work, even after changing “~~~” to “\~\~\~”. is there any way to debug this?
ehamberg
Incredulous, I tried this myself. You are absolutely correct that it doesn't work, and I have not idea why. My guess is it has something to do with the `~`. I'll keep playing with it.
sleepynate
I suppose you have to create a syntax group with the containedin keyword. see :help :syn
Benoit
A: 

This works for me. Maybe it is a starting point for further digging...

Habi
Thank you so much! This works perfectly.
ehamberg