Update (I did do it)
If you make a list of highlight
names first, you can use these to set the current highlight colour to the gui terminal using the functions synIDattr
(syntax ID attribute) and hlID
(highlight ID).
First make a list of highlight names with a foreground value fg
or the background value bg
.
let g:term_colourscheme_colours = [
\ { 'hi': 'Vertsplit', 'type': 'fg' },
\ { 'hi': 'Normal', 'type': 'fg' },
\ { 'hi': 'Conditional', 'type': 'fg' },
\ { 'hi': 'Special', 'type': 'fg' },
\ { 'hi': 'UnderLine', 'type': 'fg' },
\ { 'hi': 'Cursor', 'type': 'bg' },
\ { 'hi': 'Operator', 'type': 'fg' },
\ { 'hi': 'Error', 'type': 'bg' },
\ { 'hi': 'MoreMsg', 'type': 'fg' },
\ { 'hi': 'Type', 'type': 'fg' },
\ { 'hi': 'Directory', 'type': 'fg' },
\ { 'hi': 'Boolean', 'type': 'fg' },
\ { 'hi': 'Normal', 'type': 'bg' },
\ { 'hi': 'FoldColumn', 'type': 'fg' },
\ { 'hi': 'Define', 'type': 'fg' },
\ { 'hi': 'StatusLine', 'type': 'fg' }
\]
The position matters, so if you don't like these you can swap them around, or even change the hi
values (do :hi Directory
to see the hex codes for the Directory highlight for example).
I use the ap/vim-css-color
plugin which will shows me colours if I have hex codes on the screen (...it's awesome).
The next part is a couple of functions to map over this list and set each item using term_setansicolors
:
function MapAnsiTermColours(key, val)
silent! let l:colour = synIDattr(hlID(a:val.hi), a:val.type)
if len(l:colour)
return l:colour
else
return term_getansicolors(bufnr())[a:key]
endif
endfunction
let g:MapAnsiTermFunc = function("MapAnsiTermColours")
function SetAnsiTermColours()
silent! call term_setansicolors(bufnr(), map(g:term_colourscheme_colours, g:MapAnsiTermFunc))
endfunction
Then the last bit is to call SetAnsiTermColours
when a terminal buffer loads:
autocmd TerminalOpen * silent! call SetAnsiTermColours()