Highlighting parenthesized blocks

已查看 20 次
跳至第一个未读帖子

Chris Jones

未读,
2019年11月11日 19:20:162019/11/11
收件人 vim_use
I would need to highlight blocks of text delimited by opening/closing parentheses of any given type (regular, square, curly, squiggly, etc.).

For instance:

'… this is some text (here is a parenthesized block) that I would like to stand out.'

then a few lines down:

'… more text an here again (I have another parenthesized block) that I also want highlighted.

This one is simple enough… after I ':set hls' and search via '/(.*)' the parenthesized text is matched by the regex and highlighted as specified by the color scheme.

It gets a little less obvious when some of the parenthesized blocks may span more than a single lines.

Is there any way this can be done via vim regular expressions?

N.B. I know about the matching paren thingy but that is not what I want — I want the whole 'opening paren+text+closing paren' to stand out.

The context is that I have some rather large markdown files to inspect with numerous inline footnotes whose syntax is:

'^[ footnote ]'

and I am looking for a reliable way to make such footnotes stand out so I can (1) spot them at a glance and (2) easily check that they are syntaxically AOK.

To keep it simple I am not concerned about the possiblity of having square bracketed text within the footnotes.

Thanks,

CJ

Tony Mechelynck

未读,
2019年11月11日 21:42:482019/11/11
收件人 vim_use
This might not be exactly what you're asking for but it has the
advantage of working out of the box:

By default (i.e. when the matchparen global plugin is enabled, which
is the default), when the cursor is on a bracket, Vim highlights that
and the matching opposite bracket (if the latter is visible); and even
if they are too far from each other to be seen together, hitting % in
Normal mode jumps from one to the other. Which brackets are regarded
as "paired" depends on the 'matchpairs' option, whose default is
(:),{:},[:] — it is possible to match also < with > by adding

set matchpairs+=<:>

in one's vimrc; but this matching works only if the starting and
ending brackets are different: you can (by a proper setting) have it
match « with », or “ (typographic "double-6" quote) with ”
(typographic "double-9" quote) but not " with itself.

Matching is done recursively (skipping over embedded bracket pairs),
and, if the matchit plugin is enabled (which is the default) a bracket
within quotation marks won't be matched with a bracket outside of any
quote.

Best regards,
Tony.

Chris Jones

未读,
2019年11月12日 14:02:542019/11/12
收件人 vim_use
Thanks… but no thanks… :( I remember spending some time disabling / rid getting of that plugin that had all my parentheses jumping around like Mexican frijoles at one point… and sorry if I was unclear… I do not want to highlight the opening and ending inline footnotes markers. What I need is to highlight the entire footnote text so such footnotes are easy to spot at a glance in lengthy markdown files.

This should be taken care of by the markdown.vim syntax file but it does not work on my debian system either with my personal colorscheme or with the 'default' colorscheme that ships with vim 8.1.

So instead of opening an issue with the author of the syntax file (one Tim Pope as per the comments in the file) I thought it would be in my best interest to find a workaround that does the job now when I need it rather than wait for weeks… months… years… for a hypothetical fix… when I will have moved on to other things and completely forgotten my markdown footnotes headaches. Fixing or should I say 'fixing'… the syntax file is not even something straightforward that I want to look into since it may very well turn out that the particular flavour of markdown that I use among many others (pandoc markdown) may not follow the syntax the general markdown rules that the markdown.vim files was written for in the first place.

That's why I started looking at a way to do the highlighting manually via a ':set hls'+'some regex…' that would match '^[' followed by any non ']' sequence of characters including newlines until it reached the ending square bracket. I quickly found one that more or less works when the footnote spans only two lines and its text does not contain closing square brackets… (/\^[.*\n.*\]) or something…) but I was unable to find a way to extend this logic to match footnotes that span more than 2 lines. Basically I would need to repeat the 'sequence of non-] characters ending with a new line' bit any number of times until it reached the final ']'. Not even sure that this is something that regular expressions are supposed to be able to do for that matter.

I have a feeling my only option it to try writing a modified version of the standard markdown.vim file mimicking the way such blocks are handled by html.vim for stuff like italicised and bold text?

Any other suggestions?

Thanks,

CJ   

Chris Jones

未读,
2019年11月12日 15:19:342019/11/12
收件人 vim_use
I just found a pandoc.vim syntax file at github that appears to does the job… only had to do a ':set cole=0' to get rid of the fancy 'conceal' gimmickry and it seems to highlight inline foonotes reliably.

Sorry fo the noise.

CJ

On Monday, November 11, 2019 at 7:20:16 PM UTC-5, Chris Jones wrote:
回复全部
回复作者
转发
0 个新帖子