Any easy way to handle large number of keywords in gvim custom syntaxfile

88 views Asked by At

I was writing a custom gvim syntax file and the number of keywords are huge (about 1000) so is there any easy way of handling that in .vim syntax files...

may be like adding all the keywords in one file and ask vim to treat everything in that file as keywords,

I have a mytype.vim file with different set of rules and i am not sure its a good idea to add those 1000 keywords in there.

any other solution or suggestions are also welcome :)

1

There are 1 answers

3
Ingo Karkat On BEST ANSWER

You can pass a list of keywords to the :syntax keyword command. Excerpt from $VIMRUNTIME/syntax/vim.vim:

syn keyword vimCommand contained a arga[dd] ar[gs] bar bn[ext] breaka[dd] bu bw[ipeout] caddf[ile] cd cgete[xpr] checkt[ime] cmdname cnf com con[tinue] cq[uit] cw[indow] delc[ommand] diffg[et] diffpu[t] dig[raphs] dr[op] earlier el[se] endfo[r] ene[w] filename fin[d] folddoc[losed] fu[nction] gui helpg[rep] ia in j[oin] kee[pmarks] laddf[ile] lb[uffer] le[ft] lgetb[uffer] l[ist] lN lNf lo[adview] lpf[ile] luado mak[e] menut[ranslate] mks[ession] mod[e] n new noautocmd on[ly] pc[lose] popu p[rint] promptr[epl] ptn pts[elect] py[thon] quote redi[r] res[ize] ru rv[iminfo] sbf[irst] sbr[ewind] scscope sfir[st] sim[alt] sme snoreme spe spellw[rong] star st[op] sunmenu syn ta tabf[ind] tabnew tabr[ewind] tcld[o] tj[ump] tN tp[revious] tu u[ndo] unlo[ckvar] verb[ose] vim[grep] vne[w] win wn[ext] w[rite] xa[ll] XMLent xunme

So, the overhead is small, and I would recommend just that.

Of course, you can use Vim metaprogramming, i.e. read the keywords from a file (via readfile()) / List and dynamically build the :syntax keyword commands, but only do this if you have a real need (e.g. when the keywords differ by language version):

for keyword in ['foo', 'bar', 'baz']
    execute 'syntax keyword' keyword
endfor

The parsing overhead for keywords is less than for matches or regions, so (a few) thousand keywords should be handled just fine by Vim.