7

I use GVim with the gruvbox colorscheme. When I open a terminal inside vim with :term, the colors are different, it looks like another colorscheme is applied.

enter image description here

The other terminals I use (urxvt and xfce4-terminal) also look nothing like what I see in the vim terminal.

Where is the coloscheme of the vim terminal buffer configured and how can I change it ?

1
  • Why do you think it is different in terminal in your case? Normal foreground and background in terminal looks the same as in your buffer.
    – Maxim Kim
    May 21, 2020 at 8:38

3 Answers 3

4

In GVim, you can control the 16 ANSI colors used by your terminal with the g:terminal_ansi_colors variable.

See :help g:terminal_ansi_colors:

In GUI mode or with 'termguicolors', the 16 ANSI colors used by default in new terminal windows may be configured using the variable g:terminal_ansi_colors, which should be a list of 16 color names or hexadecimal color codes, similar to those accepted by highlight-guifg. [...]

The term_setansicolors() function can be used to change the colors, and term_getansicolors() to get the currently used colors.

2
  • There's also the Terminal highlight group to define default foreground and background colors. But I think in your case the 16 ANSI colors is where you're seeing the differences... Right?
    – filbranden
    May 21, 2020 at 8:46
  • But where do I find the colors of the current vim colorscheme that I would like to extend to the terminal buffer?
    – kksagar
    Mar 21 at 10:39
4

In modern vim/neovim there is :h g:terminal_ansi_colors (vim) or 16 of g:terminal_color_0 .. g:terminal_color_15 (neovim).

If you open gruvbox colorscheme you use, you will find those definitions there (most probably).

Basically:

  1. your whatever terminal can have palette of base 16 colors defined (there are defaults for each type of terminal, but you can also redefine it).
  2. In Vim when you open a :term those default/redefined base 16 colors are applied to it unless you or a colorscheme again redefine them with g:terminal_ansi_colors to match your colorscheme
4

I had the same question (I am using vim 8.2) and a google search brought me here. I searched vim help for g:terminal_ansi_colors and made a list as they suggested of rgb values for gruvbox using the neutral and bright colors listed here: https://github.com/morhetz/gruvbox-contrib/blob/master/color.table. Then I searched more and found you need to set highlight Terminal guibg= and same for guifg to have a gruvbox background. This code in vimrc gave me a nice gruvbox themed terminal:

let g:terminal_ansi_colors = [
  \'#282828', '#CC241D', '#98971A', '#D79921',
  \'#458588', '#B16286', '#689D6A', '#D65D0E',
  \'#fb4934', '#b8bb26', '#fabd2f', '#83a598',
  \'#d3869b', '#8ec07c', '#fe8019', '#FBF1C7' ]

highlight Terminal guibg='#282828'
highlight Terminal guifg='#ebdbb2'
1
  • Note that you can write :highlight Terminal guibg=… guifg=… on the same line.
    – D. Ben Knoble
    Sep 7, 2022 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.