Loading ...
Sorry, an error occurred while loading the content.

syntax highlighting with regular expressions

Expand Messages
  • Mark Volkmann
    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
    Message 1 of 4 , Jul 5, 2014
    • 0 Attachment
      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?

      --
      R. Mark Volkmann
      Object Computing, Inc.

      --
      --
      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@....
      For more options, visit https://groups.google.com/d/optout.
    • Ben Fritz
      ... Why is it important that foo and baz don t get matched? Do you really need them not part of the match, or is it sufficient if they are matched but not
      Message 2 of 4 , Jul 5, 2014
      • 0 Attachment
        On Saturday, July 5, 2014 5:26:15 PM UTC-5, Mark Volkmann 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?

        Why is it important that foo and baz don't get matched? Do you really need them not part of the match, or is it sufficient if they are matched but not highlighted? Or, highlighted differently from "test"?

        --
        --
        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@....
        For more options, visit https://groups.google.com/d/optout.
      • Benjamin Klein
        ... 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
        Message 3 of 4 , Jul 5, 2014
        • 0 Attachment
          On Jul 5, 2014, at 5:24 PM, Mark Volkmann <r.mark.volkmann@...> 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@....
          For more options, visit https://groups.google.com/d/optout.
        • BPJ
          ... having difficulty. ... the end regex. ... precedes baz or qux . ... need them not part of the match, or is it sufficient if they are matched but not
          Message 4 of 4 , Jul 6, 2014
          • 0 Attachment


            Den 6 jul 2014 01:03 skrev "Ben Fritz" <fritzophrenic@...>:

            >
            > On Saturday, July 5, 2014 5:26:15 PM UTC-5, Mark Volkmann 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?
            >
            > Why is it important that foo and baz don't get matched? Do you really need them not part of the match, or is it sufficient if they are matched but not highlighted? Or, highlighted differently from "test"?

            Just out of curiosity (I'm in a vim-less environment ATM) would start='\%(foo\)\@<=' end='\%(bar\)\@=' work? Would it be undesirable even if it does work?

            --
            --
            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@....
            For more options, visit https://groups.google.com/d/optout.
          Your message has been successfully submitted and would be delivered to recipients shortly.