vim colorschemes not changing background color

后端 未结 11 1823
北恋
北恋 2021-01-30 08:43

I try to apply various color schemes in vim that I have seen on the net. Whatever scheme I choose, the background remains white, even though screenshots of the applied scheme sh

相关标签:
11条回答
  • 2021-01-30 09:16

    Terminals are usually limited to 256 colors while GUI are only limited by color depth of your desktop environment, typically 2^32.

    So even if there is lots of vim color scheme available around, implicitly they are often designed for the GUI and won't work for the terminal version.

    If you look at color schemes on vim.org, there is often a mention of GUI or 256. So you have to chose which to use depending on the context.

    To convert a GUI scheme to terminal you can use the following plugin : CSApprox.

    You can also use a different colorscheme depending on the context, add the following in your .vimrc:

    if has("gui_running")  
        colorscheme [using any color you want]  
    else  
        colorscheme [using 256 colors]  
    endif  
    
    0 讨论(0)
  • 2021-01-30 09:16

    I think the problem could be the way the default color is changed by the colorscheme. I've looked at some colorschemes that set default merely by:

    set background=light
    

    or

    set background=dark
    

    Not sure what limitations of those are. I don't think those work in terminals.

    In any case, you should be able to manually set background in a terminal by using the 'Normal' highlight. Insert it into a spot before most of the 'hi' commands in the colorscheme file and it should provide defaults they will work with. For example:

    hi Normal ctermbg=White ctermfg=Black guifg=Black guibg=White
    

    Change ctermfg (color terminal foreground) and ctermbg (color terminal background) to be whatever you want (or whatever color you were expecting to see in the colorscheme but now aren't seeing). (Remember, though, if the colorscheme already has a setting for hi Normal then this probably isn't your problem.)

    For ctermbg and ctermfg you can enter color names, but I think there is only a fairly limited number: Black DarkBlue DarkGreen DarkCyan DarkRed DarkMagenta Brown, DarkYellow LightGray, LightGrey, Gray, Grey DarkGray, DarkGrey Blue, LightBlue Green, LightGreen Cyan, LightCyan Red, LightRed Magenta, LightMagenta Yellow, LightYellow White

    Otherwise you should be able to use a number from 0 to 255 in place of the color name. Or this script gives rough idea, and lets you see how you could also set up to use more color names: Vim script with color settings

    Also, there are a number of scripts that help you use or convert colorschemes written for gui for use with cterm. E.g.,:

    Colorscheme support for cterm

    Does the overall settings for the terminal window have something to do with it?
    

    Maybe, but I'm pretty sure a properly written Vim colorscheme will override any terminal settings you've made. At least they do for me in Windows and on Ubuntu. . .

    0 讨论(0)
  • 2021-01-30 09:16

    I had the same problem and found out that the answer to this question is actually threefold, where fixing only two of the three isn't enough. You'll need to have:

    1. 256-color support in your terminal - Putty with default settings does have this

    2. Vim has to recognize that the terminal is 256-color capable: "set t_Co=256" in your .vimrc will do it

    3. The color scheme needs to have support for color terminals with ctermbg and ctermfg attributes for highlights, not just the gui*-versions. http://www.vim.org/scripts/script.php?script_id=2682 should be able to provide these automatically, and CSApprox I'm using most definitely does, but requires either +gui -compiled Vim or a recent enough Vim version (7.3 or newer).

    The third one seems to be the most commonly missed requirement. I wrote a short piece on my own fumblings on this subject just this morning: http://codeandlife.com/2013/09/22/vim-colorschemes-with-putty-aka-gui-vs-xterm-color256/

    Final gotcha that happened to me while trying different settings was that when the colors did work, only areas of screen with text had the proper background color. Re-checking Putty Terminal setting "Use background colour to erase screen" fixed that final issue for me.

    0 讨论(0)
  • 2021-01-30 09:20

    I'm adding a second answer from me because it's very different from my first answer and may point to actual problem.

    If you look at the actual website for the colorscheme here: Molokai website

    you will see a question very similar to yours. Here's answer given, which suggests trying command :set t_Co=256 in your vimrc to see if it fixes things:

    "- Make sure you’re using a console terminal capable of 256 colors; not all of them do (particularly on mac). You might need to explicitly force Vim to use that by doing “set t_Co=256″ on your .vimrc file. - The windows console is well… totally unsupported, that only does 16 colors so it’s a mess"

    0 讨论(0)
  • 2021-01-30 09:20

    In linux I had export TERM=xterm-256color in my .bashrc. That caused vim to look like this (after setting set t_Co=256):

    Vim looks with molokai theme before fixing TERM variable

    When I removed that line from my .bashrc and opened a new terminal (exec bash didn't do it) This is what I get:

    Vim looks with molokai theme after fixing TERM variable

    0 讨论(0)
  • 2021-01-30 09:24

    You need to add set termguicolors to your ~/.vimrc

    I tested t_Co=256 and other options, but none worked, only set termguicolors

    After this you can use the command set bg=light or set bg=dark to see witch one looks better (some vim color schemes accept both options).

    Here is a list of terminals that are compatible with termguicolors: https://gist.github.com/XVilka/8346728#now-supporting-true-color

    0 讨论(0)
提交回复
热议问题