As I was currently editing tables in markdown, I wanted to color table cells based on content : green for yes
, red for no
and yellow for ?
. So I made a PR about this for the plugin vim-table-mode
.
But it’s possible to implement it outside of the plugin by adding the following in your vimrc
:
syntax match Table '|.\+|' contains=yesCell,noCell,maybeCell
syntax match yesCell '|\@<= *yes[^|]*' contained
syntax match noCell '|\@<= *no[^|]*' contained
syntax match maybeCell '|\@<= *?[^|]*' contained
hi yesCell cterm=bold ctermfg=10 ctermbg=2
hi noCell cterm=bold ctermfg=9 ctermbg=1
hi maybeCell cterm=bold ctermfg=11 ctermbg=3
It will render as the following :
You can also implement coloring based on cell prefix :
syntax match Table '|.\+|' contains=yredCell,greenCell,yellowCell,blueCell,whiteCell,darkCell
syntax match redCell '|\@<= *r:[^|]*' contained
syntax match greenCell '|\@<= *g:[^|]*' contained
syntax match yellowCell '|\@<= *y:[^|]*' contained
syntax match blueCell '|\@<= *b:[^|]*' contained
syntax match whiteCell '|\@<= *w:[^|]*' contained
syntax match darkCell '|\@<= *d:[^|]*' contained
hi redCell ctermfg=9 ctermbg=1
hi greenCell ctermfg=10 ctermbg=2
hi yellowCell ctermfg=11 ctermbg=3
hi blueCell ctermfg=12 ctermbg=4
hi whiteCell ctermfg=0 ctermbg=15
hi darkCell ctermfg=15 ctermbg=0
This will render as the following :