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

Help with VIM syntax region regex please....

Expand Messages
  • wombatvvv
    Hello, I m doing something a little complex with my syntax highlighting, and I m having a problem. I want if-blocks to be highlighted differently. I want the
    Message 1 of 4 , Jan 1, 2012
    • 0 Attachment
      Hello,

      I'm doing something a little complex with my syntax highlighting, and I'm
      having a problem.

      I want if-blocks to be highlighted differently. I want the if-block to start
      with the word "if" and end one-space before the { symbol, but ONLY match if
      there is a { symbol. In other words, not to match if the if-statement is a
      one or two-line statement that doesn't use curly braces.

      So far, I have this:

      syntax region blockStartLvl1 start=/if/ end=/{/me=e-1
      contains=@blockStartLvl1Contents

      Which works fine, as long as the if statement is followed by curly braces.

      --
      View this message in context: http://vim.1045645.n5.nabble.com/Help-with-VIM-syntax-region-regex-please-tp5113772p5113772.html
      Sent from the Vim - General mailing list archive at Nabble.com.

      --
      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
    • Karthick Gururaj
      ... Just curious, which language is this for? C? So, if I understand correctly, if (i 0) { printf( Hello! ); } ...should match and if (i 0) printf( Hello );
      Message 2 of 4 , Jan 2, 2012
      • 0 Attachment
        On Mon, Jan 2, 2012 at 5:40 AM, wombatvvv <captaineight@...> wrote:
        >
        > Hello,
        >
        > I'm doing something a little complex with my syntax highlighting, and I'm
        > having a problem.
        >
        > I want if-blocks to be highlighted differently. I want the if-block to start
        > with the word "if" and end one-space before the { symbol, but ONLY match if
        > there is a { symbol. In other words, not to match if the if-statement is a
        > one or two-line statement that doesn't use curly braces.

        Just curious, which language is this for? C?
        So, if I understand correctly,
        if (i>0) {
        printf("Hello!");
        }

        ...should match and
        if (i>0)
        printf("Hello");

        ..should not match?

        And when it does match, the "if (i>0)" must get highlighted.


        > So far, I have this:
        >
        > syntax region blockStartLvl1 start=/if/ end=/{/me=e-1
        > contains=@blockStartLvl1Contents
        >
        > Which works fine, as long as the if statement is followed by curly braces.
        What is the problem then?

        Btw, a perhaps syntax match would be simpler?
        syntax match blockStart "\<if\>.*\ze{"

        --
        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
      • wombatvvv
        Yes, that is correct. If I explain a bit, it may make my intentions clearer. What I am writing is a syntax file the does rainbow code colouring for different
        Message 3 of 4 , Jan 2, 2012
        • 0 Attachment
          Yes, that is correct.

          If I explain a bit, it may make my intentions clearer. What I am writing is
          a syntax file the does "rainbow" code colouring for different code-blocks as
          well as different bracket levels. It's been complex, but it almost works.
          This is one of the last issues I have to resolve.

          * http://vicwebster.net/images/screen-code.gif Here is a screenshot *
          demonstrating how it looks at the moment. The problem is, that if the
          if-statements (or for/try/catch/whatever-statements) are only one-liners,
          this will screw everything up, as the highlighting will be looking for an
          opening { symbol.

          I will experiment with your syntax match idea.

          Thanks very much for helping.




          --
          View this message in context: http://vim.1045645.n5.nabble.com/Help-with-VIM-syntax-region-regex-please-tp5113772p5115512.html
          Sent from the Vim - General mailing list archive at Nabble.com.

          --
          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
        • wombatvvv
          Actually, don t worry about. I went with a simpler solution that probably makes more sense anyway. (If, while, for, etc. block-headings are highlighted the
          Message 4 of 4 , Jan 2, 2012
          • 0 Attachment
            Actually, don't worry about.

            I went with a simpler solution that probably makes more sense anyway. (If,
            while, for, etc. block-headings are highlighted the same colours as their
            containing block, not a new one).

            * http://vicwebster.net/images/screen-code2.gif Screenshot here * if you're
            interested. As you can see, it works both with "one-line" if statements, as
            well as "block" if statements.

            BTW, I am making it for all C-style languages. It works for PHP and
            JavaScript and I can't see any reason it wouldn't work for C++,C, Java, etc.
            I guess it depends what you like. I showed it to some colleagues who didn't
            like it. But for me personally, I find it hugely more useful to have
            different levels of blocks & brackets highlighted than a variable or an
            operator (I can clearly see what they are no matter what colour they are!).

            ;)

            Thanks for your help.

            --
            View this message in context: http://vim.1045645.n5.nabble.com/Help-with-VIM-syntax-region-regex-please-tp5113772p5115577.html
            Sent from the Vim - General mailing list archive at Nabble.com.

            --
            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
          Your message has been successfully submitted and would be delivered to recipients shortly.