>
> I am assuming that you have output like this:
>
> -------------------------------------------
> | Field1 | Field2 | Field3 | Field4 | ... |
> -------------------------------------------
> | Value1 | Value2 | Value3 | Value4 | ... |
> -------------------------------------------
Exactly !
> In which case you might want to try something like this:
>
> syntax match Border '^-\+$'
> syntax match Border '^|' nextgroup=Col1
> syntax match Col1 '[^|]\+|' contained nextgroup=Col2
> syntax match Col2 '[^|]\+|' contained nextgroup=Col3
> syntax match Col3 '[^|]\+|' contained nextgroup=Col4
> syntax match Col4 '[^|]\+|' contained [ ... etc ... ]
>
> syntax match Border "|" contained containedin=Col1,Col2,Col3,Col4
>
> hi link Border Error
> hi link Col1 Macro
> hi link Col2 Type
> hi link Col3 Statement
> hi link Col4 String
> [ ... etc ... ]
>
> This should highlight each column in a different color for you. In case this
> doesn't help you, the following might help you:
Unfortunately it took till now to discover you mail ;)
I ended up trying this:
---------------------------------------------------------------------
hi def link Color1 Comment
hi def link Color2 Function
hi def link Color3 Label
hi def link Color4 Define
hi def link Border Error
hi def link DummyColor Underlined
" add display option
function! AddColumnSynMatches()
let colors = ['Color1','Color2','Color3','Color4']
let sep='[|\t]' " tab or |
let non_sep='[^|\t]'
let sep='[|\t]'
let start_line='^\s*'
let dummyColor="Ignore"
let color_list=join(colors,',')
" This is used to start the chain using nextgroup=colors[0]
exec 'syn match '.dummyColor." '".start_line."' nextgroup=".colors[0].'
transparent'
for i in range(0,2) "len(colors)-1)
let color = colors[i % len(colors)]
let next_color = colors[(i+1) % len(colors)]
let regex=non_sep.'\+'.sep
exec 'syn match '.color." '".regex."' containedin=foo nextgroup=".next_color
echo 'syn match '.color." '".regex."' containedin=foo nextgroup=".next_color
endfor
echo "done"
" This border idea is from Peter
exec 'syntax match Border "|" contained containedin='.join(colors,",")
endfunction
call AddColumnSynMatches()
" outdated
command! InsertTestline normal oa<tab>b<tab>c<tab>d<tab>e<tab>f<tab>g<tab>h<tab>
---------------------------------------------------------------------
But I can't see why it does'nt work.
Explanation:
exec 'syn match '.dummyColor." '".start_line."' nextgroup=".colors[0].'
transparent'
starts highlighting the line. nextgroup tells vim to start with Color1
for i in range(0,2) "len(colors)-1)
let color = colors[i % len(colors)]
let next_color = colors[(i+1) % len(colors)]
let regex=non_sep.'\+'.sep
exec 'syn match '.color." '".regex."' containedin=foo nextgroup=".next_color
echo 'syn match '.color." '".regex."' containedin=foo nextgroup=".next_color
endfor
This should add support for 3 columns (use len(colors)-1 to support as much as
you have RAM..
contained=foo should ensure that they don't start on their own (because foo
isn't defined and nextgroup overrides this behaviourr anyway)
But all I can see is the line beeing highlighted in Error (the color of the
dummy start line syntax area)
Try it out by using
:source|InsertTestline
Do you see what I've done wrong?
Marc Weber