Keith Kaple schrieb:
> Ok, I give up ;-)
>
> I'm trying to write a syntax file for a "pipe" delimeted file, lines
> look something like the example below.  I started off ok and got the
> first number and timestamp via syn match, but then thought there is
> probably an easier way to do regexp tagging on the fields based on the
> delimeter character, but I can't seem to figure out the regexp syntax.
>
> 00001 | timestamp | 001| text4 | text5 | text6 | text7 | text8
>
>
> Say I want to define Field4, I was trying stuff like:
>
> syn match FieldFour "^[^|]+|[^|]+|[^|]+|[^|]+|"
>
> which I though would be "any number of anything not a pipe, then a
> pipe" repeated four times.  Also tried escaping those pipes in
> brackets too thinking | was interpreted as "or" but not sure if that
> is correct in this flavor of regexp.
>
> Also tried a few unsuccessfull versions of:
>
> syn match FieldFour "^(.*|){5}"
>
> How do you match "just the text after the Nth pipe?"
>
>
> These worked for the first two fields.., but going beyond that without
> just using the occurance of the delimiter somehow probably isn't worth
> it..
>
> syn match TimeStamp "^\d\d\d\d\d\d\d\d\d| \d\d\d\d/\d\d/\d\d
> \d\d:\d\d:\d\d\.\d\d\d" syn match IndexNumber "^\d\d\d\d\d\d\d\d\d"
> containedin=TimeStamp contained
>
>
> thanks,
>
> Keith

To get distinct highlighting for each field, try the following:

    syn match pipeFirst /^[^|]*/ nextgroup=pipeSecond
    syn match pipeSecond /|[^|]*/hs=s+1 contained nextgroup=pipeThird
    syn match pipeThird /|[^|]*/hs=s+1 contained nextgroup=pipeFourth
    syn match pipeFourth /|[^|]*/hs=s+1 contained nextgroup=pipeFifth
    syn match pipeFifth /|[^|]*/hs=s+1 contained

    hi link pipeFirst  Constant
    hi link pipeSecond Identifier
    hi link pipeThird  Statement
    hi link pipeFourth PreProc
    hi link pipeFifth  Type

and so on ... and replace the "pipe" prefix with a more appropriate name ;)

-- 
Andy

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to