MacVim color scheme has the right color, but vim through Terminal doesn't
The terminal colours are set separately from :colorscheme
, there's a function you can use to see what the current colours are called term_getansicolors
.
There's also another one called term_setansicolors
. The get recieves the buffer number that the terminal is on and returns an array of hex codes...
:echo term_getansicolors(bufnr())
You can also set the result to your register with:
:let @" = join(term_getansicolors(bufnr))
Then you can paste them to have a look at the actual colours and change them.
The next bit I haven't got around to trying but theoretically you can just make your own array of hex colours and pass them into term_setansicolors
:
:call term_setansicolors(bufnr(), [ ...my new colours ])
After that you could make your own mapping that opens the terminal with that function call included in it, or do something more complicated that gets the colours from your current colorscheme and set them automatically.
I might have a look at doing it so I'll come back here and post more if it works.
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': 'UnderLined', '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()