Saturday, July 5, 2014

Re: syntax highlighting with regular expressions

On Jul 5, 2014, at 5:24 PM, Mark Volkmann <r.mark.volkmann@gmail.com> wrote:

> I'm trying to use "syntax region" with start=regex and end=regex, but having difficulty.
> I want the region to match what follows the start regex and precedes the end regex.
> For example, say I want to match whatever follows "foo" or "bar" and precedes "baz" or "qux".
> So in these two examples, the word "test" should be highlighted:
>
> footestbaz
> bartestqux
>
> Can someone show me an example that is similar to this?

I just threw this together in terminal Vim. Hopefully it's some help. What I think may be key is that you need to set the `matchgroup`, which is the group the `start` and `end` patterns belong to.

**************************************************

syntax region testGroup matchgroup=endsGroup
\ start=/foo/ end=/baz/

highlight testGroup ctermfg=lightblue

finish

fooyo this is text baz

**************************************************

"yo this is text" is highlighted in blue when I source the script.

Ben

--
b

Sent from my iPhone

--
--
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: