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.