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
Does the overall settings for the terminal window have something to do with it?
Yes, terminal parameters override vim parameters (at least in OSX and iTerm). For example, I have a following script in /Users/[username]/.bashrc
setBackground() {
osascript -e "tell application \"iTerm\"
set current_terminal to (current terminal)
tell current_terminal
set current_session to (current session)
tell current_session
set background color to $1
end tell
end tell
end tell"
}
vim() {
(setBackground "{65025,65025,65025}" &)
(exec vim $*)
}
The above remaps terminal vim command to execute a background color change before executing vim. Background color function is applescript (I copied the script from somewhere...). It works for iTerm. I belive that you can adapt this to work with terminal (apple product + apple script -> should work).
br,
Juha
Use this rule if you use Vim through SSH:
Add to your local .bashrc
:
export TERM=xterm-256color
Remove from .bashrc
any TERM
definitions.
If you use same .bashrc
on both (local and remote), use temporary environment variable and never set TERM
globally:
alias color-ssh='TERM=xterm-256color ssh user@host'
This works for me for switching backgrounds:
colorscheme hemisu
function! g:ToggleBackground()
if &background != 'dark'
set background=dark
else
set background=light
colorscheme hemisu
endif
endfunction
nnoremap <silent> <F3> :call g:ToggleBackground()<CR>
Also try setting light background to something like ctermbg=231
, so that tmux handles it better.
I have this in my .vimrc and it solved this problem for me using while using PuTTY.
set t_Co=256
set background=dark
colorscheme mustang
highlight Normal ctermbg=NONE
highlight nonText ctermbg=NONE
It's important to load the colorscheme before the ctermbg settings in .vimrc because they need to override the same ones set by the colorscheme. This also means you can't switch colorscheme while Vim is running and expect it to work.
I have similar issue that the background color of indentation guides (nathanaelkane's vim-indent-guides) cannot be displayed in my Windows Cygwin's mintty terminal.
I solved the issue with a line Term=xterm-256color
in ~/.minttyrc (equivalent to set via mintty's Options GUI: Terminal -> Type -> xterm-256color
. This has the effect export TERM=xterm-256color
. Without this, mintty default to TERM="xterm", which result in vim's t_Co=8
(instead of t_Co=256
) and cannot show some background color.
Checklist:
echo $TERM
in bash should give xterm-256color
.:set t_Co
should give t_Co=256
.