termguicolors in vim makes everything black and white

The idea is that by using set termguicolors in Vim, I should get the colorscheme (gruvbox) to look in my terminal (st, has true color support) exactly like in GVim. But all I get is white text on black background.

The part in vimrc which sets the colorscheme:

set background=dark
colorscheme gruvbox
set termguicolors

Upvotes: 26

Views: 39637

Answers (2)

CervEd
CervEd

Reputation: 4263

What is $TERM? set termguicolors only seems to work if TERM is xterm*.

I set this to make it work with other things, like screen/tmux

if !has('gui_running') && &term =~ '\%(screen\|tmux\)'
  let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
  let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
set termguicolors

This way vim uses truecolor for both xterm* and screen*/tmux*

Upvotes: 5

yolenoyer
yolenoyer

Reputation: 9445

You might read :h xterm-true-color.

I'm using st as well, and indeed, setting termguicolors gave me black and white colors only.

But by following the advice in the help, I added the following:

let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"

Then colors appeared again. Hope it can help.

Here is the whole excerpt from :h xterm-true-color:

Vim supports using true colors in the terminal (taken from |highlight-guifg| and |highlight-guibg|), given that the terminal supports this. To make this work the 'termguicolors' option needs to be set. See https://gist.github.com/XVilka/8346728 for a list of terminals that support true colors.

Sometimes setting 'termguicolors' is not enough and one has to set the |t_8f| and |t_8b| options explicitly. Default values of these options are "^[[38;2;%lu;%lu;%lum" and "^[[48;2;%lu;%lu;%lum" respectively, but it is only set when $TERM is xterm. Some terminals accept the same sequences, but with all semicolons replaced by colons (this is actually more compatible, but less widely supported):

     let &t_8f = "\<Esc>[38:2:%lu:%lu:%lum"
     let &t_8b = "\<Esc>[48:2:%lu:%lu:%lum"

These options contain printf strings, with |printf()| (actually, its C equivalent hence l modifier) invoked with the t_ option value and three unsigned long integers that may have any value between 0 and 255 (inclusive) representing red, green and blue colors respectively.

Upvotes: 30

Related Questions