I have defined a custom file type with these lines:
syn region SubSubtitle start=+=+ end=+=+
highlight SubSubtitle ctermbg=black ctermfg=DarkGrey
syn region Subtitle start=+==+ end=+==+
highlight Subtitle ctermbg=black ctermfg=DarkMagenta
syn region Title start=+===+ end=+===+
highlight Title ctermbg=black ctermfg=yellow
syn region MasterTitle start=+====+ end=+====+
highlight MasterTitle cterm=bold term=bold ctermbg=black ctermfg=LightBlue
I enclose all of my headings in this kind of document like this:
==== Biggest Heading ==== // this will be bold and light blue
===Sub heading === // this will be yellow
bla bla bla // this will be normally formatted
However right now when ever I use an equals sign in my code it thinks that it is a title. Is there anyway that I can force a match to be only on one line?
UPDATE: My previous answer was wrong, you can do this with a region, just do
syn region SubSubtitle start=+=+ end=+=+ oneline
See :help syn-oneline
and :help syn-arguments
. Guess it shows that I can't actually run vim right now, hunh?
Previous answer
According to my reading of the :help syntax, there's no way to do this with a region. However, you could do this with a syn-match:
syn match SubSubtitle /=\@<!=[^=]*==\@!/
The /=\@<!/
says there's no =
immediately before your match, and the /=\@!/
says there's no =
immediately after, so this matches exactly one =
, a bunch of non-=
(not including newlines - to include newlines it would have to be \_[^=]
), then exactly one =
.
The rest are similar
syn match Subtitle /=\@<!=\{2}[^=]*=\{2}=\@!/
syn match Title /=\@<!=\{3}[^=]*=\{3}=\@!/
syn match MasterTitle /=\@<!=\{4}[^=]*=\{4}=\@!/
You can still do matches within syn-matches, so if you have any nesting going on, it will still work.
For example
syn match Todo /\<TODO\>/ containedin=SubSubtitle,Subtitle,Title,MasterTitle contained
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With