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

nextgroup across line border

Expand Messages
  • ZyX
    I want to create a syntax for filetype that looks like this: item0onLine0 item1onLine1 item0onLine1 item1onLine1 separatorLine item0onLine0 item1onLine0
    Message 1 of 4 , Sep 4, 2011
    • 0 Attachment
      I want to create a syntax for filetype that looks like this:

      item0onLine0 item1onLine1
      item0onLine1 item1onLine1
      separatorLine
      item0onLine0 item1onLine0
      item1onLine1 item1onLine1
      ...

      In order to do this I try

      syn match i0l0 /^item0onLine0/ nextgroup=i1l0
      syn match i1l0 / item1onLine0\n/ contained nextgroup=i0l1
      syn match i0l1 /item0onLine1/ contained nextgroup=i1l1
      syn match i1l1 / item1onLIne1\n/ contained

      , but this works on first line only. How can I have next group located on the
      next line? `item0onLine1' cannot be matched reliably on its own. `item0onLine0'
      is always matched reliably.
    • Andy Wokula
      ... Looks like you have just missed ... -- Andy -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you
      Message 2 of 4 , Sep 4, 2011
      • 0 Attachment
        Am 04.09.2011 19:52, schrieb ZyX:
        > I want to create a syntax for filetype that looks like this:
        >
        > item0onLine0 item1onLine1
        > item0onLine1 item1onLine1
        > separatorLine
        > item0onLine0 item1onLine0
        > item1onLine1 item1onLine1
        > ...
        >
        > In order to do this I try
        >
        > syn match i0l0 /^item0onLine0/ nextgroup=i1l0
        > syn match i1l0 / item1onLine0\n/ contained nextgroup=i0l1
        > syn match i0l1 /item0onLine1/ contained nextgroup=i1l1
        > syn match i1l1 / item1onLIne1\n/ contained
        >
        > , but this works on first line only. How can I have next group located on the
        > next line? `item0onLine1' cannot be matched reliably on its own. `item0onLine0'
        > is always matched reliably.

        Looks like you have just missed
        :h :syn-skipwhite
        :h :syn-skipnl

        --
        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
      • ZyX
        Reply to message «Re: nextgroup across line border», sent 22:19:37 05 September 2011, Monday ... Yes, I missed this. It is not exactly what I want: this
        Message 3 of 4 , Sep 5, 2011
        • 0 Attachment
          Reply to message «Re: nextgroup across line border»,
          sent 22:19:37 05 September 2011, Monday
          by Andy Wokula:

          > Looks like you have just missed
          >
          > :h :syn-skipwhite
          > :h :syn-skipnl
          Yes, I missed this. It is not exactly what I want: this tells vim to ignore \n,
          while I know that \n *must* be there, but this is also acceptable, thanks.

          I have also a situation where last item may be empty string and it does not work
          if one of the rules looks like /.*/. If I was able to match item0onLine1 using
          /\nitem0onLine1/ (and add nextgroup=i0l1 to i0l0) it would be better. Or somehow
          tell vim that empty string match is acceptable. I can't use `skipnl' for
          previous item: it will make /.*/ match on the next line when it is not present.

          Original message:
          > Am 04.09.2011 19:52, schrieb ZyX:
          > > I want to create a syntax for filetype that looks like this:
          > > item0onLine0 item1onLine1
          > > item0onLine1 item1onLine1
          > > separatorLine
          > > item0onLine0 item1onLine0
          > > item1onLine1 item1onLine1
          > > ...
          > >
          > > In order to do this I try
          > >
          > > syn match i0l0 /^item0onLine0/ nextgroup=i1l0
          > > syn match i1l0 / item1onLine0\n/ contained nextgroup=i0l1
          > > syn match i0l1 /item0onLine1/ contained nextgroup=i1l1
          > > syn match i1l1 / item1onLIne1\n/ contained
          > >
          > > , but this works on first line only. How can I have next group located on
          > > the next line? `item0onLine1' cannot be matched reliably on its own.
          > > `item0onLine0' is always matched reliably.
          >
          > Looks like you have just missed
          >
          > :h :syn-skipwhite
          > :h :syn-skipnl
        • Jacky Liu
          ... Don t know if I got you right but my personal experience is that too many nextgroup s was no good, it s just a hint to Vim that certain syntax groups
          Message 4 of 4 , Sep 5, 2011
          • 0 Attachment
            On Sep 5, 1:52 am, ZyX <zyx....@...> wrote:
            > I want to create a syntax for filetype that looks like this:
            >
            >     item0onLine0 item1onLine1
            >     item0onLine1 item1onLine1
            >     separatorLine
            >     item0onLine0 item1onLine0
            >     item1onLine1 item1onLine1
            >     ...
            >
            > In order to do this I try
            >
            >     syn match i0l0 /^item0onLine0/             nextgroup=i1l0
            >     syn match i1l0 / item1onLine0\n/ contained nextgroup=i0l1
            >     syn match i0l1 /item0onLine1/    contained nextgroup=i1l1
            >     syn match i1l1 / item1onLIne1\n/ contained
            >
            > , but this works on first line only. How can I have next group located on the
            > next line? `item0onLine1' cannot be matched reliably on its own. `item0onLine0'
            > is always matched reliably.
            >
            >  signature.asc
            > < 1KViewDownload

            Don't know if I got you right but my personal experience is that too
            many "nextgroup"s was no good, it's just a hint to Vim that certain
            syntax groups should get a privilege next, it doesn't ensure anything.
            If what you mean is that some text's syntax group can't be decided by
            it's own signature but the context it resides, than I suggest you use
            a structural approach:

            AAA ... XXX
            BBB ... XXX

            Say, you want to color the second 'XXX' differently because it's in
            the line begin with "BBB", then this should do:

            " syntax container
            syntax match Aline /^AAA\>.*/
            hi link Aline Normal " no color, just for containing other groups

            syntax match Bline /^BBB\>.*/
            hi link Bline Normal " the same as above

            " target syntax groups
            syntax match Aword /\<XXX\>/ containedin=Aline contained
            hi link Aword ColorA

            syntax match Bword /\<XXX\>/ containedin=Bline contained
            hi link Bword ColorB

            If you can find the appropriate container group with its own signature
            then things will get a lot easier, because with 'containedin'
            and 'contained' together, Vim won't try to match 'XXX' anywhere else.

            Just a wild guess, hope it helps.

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