Wednesday, January 9, 2019

Re: Nested syntax highlighting in vim

Am 08.01.2019 um 19:09 schrieb Gua Chung Lim:
> Hi all,
>
> I'm trying to create a syntax for my own mine.vim.
> I always highlight [words between square brackets in one line] in red.
> What if the mentioned square brackets are nested like ...
> [words [inside another brackets]]?
> I got red color only the first 3 [, [ and ].
> But the color for the last one (]) is still white.
> The relevant lines of mine.vim are as followings.
> % grep mineRed ~/.vim/syntax/mine.vim
> syn region mineRed start=+\[+ skip=+\\\\\|\\'+ end=+\]+ oneline
> hi def link mineRed SpecialChar
>
> Actually I don't know much about vim syntax highlighting.
> I copied these commands from somewhere else (mostly help.vim).
> And I then modified it to suit my needs.
>
> Any input would be highly appreciated. Thanks,

" add a contains argument:
syn clear
syn region mineRed start=+\[+ skip=+\\\\\|\\'+ end=+]+ oneline contains=mineRed
hi link mineRed SpecialChar

" the skip argument seems useless, you may want to use it to escape a closing ']' (?):
syn clear
syn region mineRed start=+\[+ skip=+\\[\\\]]+ end=+]+ oneline contains=mineRed
hi link mineRed SpecialChar

(syn clear and hi link only added for demo purposes)

--
Andy

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: