Or else, did you mean "as many colors as there are different
words in the file" .... ?
Yes exactly.
Heh. But won't you have problem with number of available colors
vs number of different words in the file ? Number of different words
in the file can be in thousands. What
do you do when number of words > number of colors ?
Its not prose, so there are not that many unique words.
You could specify that the script processes only the first n words.
Well, the following monstrosity can do the job:
function! Colorize()
let l:colornames = [ 'DiffAdd', 'DiffChange', 'DiffDelete',
'DiffText', 'ErrorMsg', 'VertSplit', 'Folded', ]
let l:found_words = {}
let l:index = 0
let l:len = len(l:colornames)
g/\w/for l:word in split(getline('.'), '\A\+') | let
l:found_words[l:word] = l:colornames[l:index] | let l:index =
(l:index + 1) % l:len | endfor
for l:key in keys(l:found_words)
exec 'syn keyword '.l:found_words[l:key].' '.l:key
endfor
endfunc
It requires Vim7. You can adjust the available l:colornames in
that first line to include whatever color names you have
available, or generate them on the fly.
The magic happens in that g// line (which hideously wraps to
three lines in my mailer, but should all be one line). It builds
a dictionary (l:found_words) mapping the expected keyword to the
next unused color, rotating through the list of available color
names.
Lastly, it iterates over that dictionary, issuing "syn keyword"
commands for each pairing.
Uuuuuugly, but it works and does what I understand you want.
Given some external utilities or a scratch buffer, something
similar could be done in pre-vim7 versions of things, but this
made a good excuse for me to try out the new lists/dictionaries
in vim7. :)
-tim
(who is too often waaaay behind the curve of upgrading vim
versions...)