Reputation: 43
Tried solutions: adding export TERM=xterm-256color
to .bashrc
and .zshrc
and also adding set t_Co=256
to .vimrc
as pointed out in the solutions to other questions.
Yes, I am using a color scheme that supports both the gui and the terminal it is here.
I use macos and hyper.app
primarily but the similar situation happens simultaneously on Terminal.app
so I guess its not a problem of the emulator.
Rather strange thing from other Stack Overflow question:
Adding this to my .vimrc
:
if &term =~ '256color'
" disable Background Color Erase (BCE) so that color schemes
" render properly when inside 256-color tmux and GNU screen.
set t_ut=
endif
changes my vim background to dark grey (I don't know where that comes from) but removing it changes it back to my terminal background color.
I will accept any solution (because I am fed up with this, getting this to work) so that I can get the hex color from the mac vim gui
using Color Picker.app
and could set it forcefully as the vim background every time i decide to change a theme.
All my config files:
I also use tmux
but the color is same with or without tmux
.
Output of :scriptnames
1: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/vimrc
2: ~/.vimrc
3: ~/.vim/autoload/plug.vim
4: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/filetype.vim
5: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/ftplugin.vim
6: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/indent.vim
7: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/syntax/syntax.vim
8: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/syntax/synload.vim
9: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/syntax/syncolor.vim
10: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/ftoff.vim
11: ~/.vim/bundle/Vundle.vim/autoload/vundle.vim
12: ~/.vim/bundle/Vundle.vim/autoload/vundle/config.vim
13: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/syntax/nosyntax.vim
14: ~/.vim/plugged/nemo/colors/nemo-dark.vim
15: ~/.vim/bundle/vim-tmux-navigator/plugin/tmux_navigator.vim
16: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/plugin/getscriptPlugin.vim
17: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/plugin/gzip.vim
18: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/plugin/logiPat.vim
19: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/plugin/manpager.vim
20: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/plugin/matchparen.vim
21: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/plugin/netrwPlugin.vim
22: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/plugin/rrhelper.vim
23: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/plugin/spellfile.vim
24: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/plugin/tarPlugin.vim
25: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/plugin/tohtml.vim
26: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/plugin/vimballPlugin.vim
27: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/plugin/zipPlugin.vim
28: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/ftplugin/python.vim
29: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/indent/python.vim
30: /usr/local/Cellar/macvim/8.0-146_1/MacVim.app/Contents/Resources/vim/runtime/syntax/python.vim
Also tried adding this to .vimrc
:
set background=dark
highlight Normal ctermbg=NONE
highlight nonText ctermbg=NONE
Here are the screenshots of the same theme and how is it rendering on
Upvotes: 1
Views: 3761
Reputation: 1
Try using https://github.com/chriskempson/base16-vim
I also posted two workarounds for background colors not working in Hyper here
This is the second workaround I posted may work for you:
"Overrides the color scheme background and makes it transparent
autocmd ColorScheme * highlight Normal ctermbg=None
autocmd ColorScheme * highlight NonText ctermbg=None
Upvotes: 0
Reputation: 196926
Given a proper $TERM
, Vim will always work correctly so hacks like:
set t_Co=256
are generally useless.
If you intend to use a 256color-ready colorscheme, $TERM
should end with 256color
:
xterm-256color prefered for general usage
screen-256color if you use Vim in screen or tmux
tmux-256color if you use Vim in tmux and your terminal emulator supports it
If possible, $TERM
should not be set at the shell level but at the terminal emulator level. In Hyper.app, this is done in the env
key of ~/.hyper.js
:
env: {TERM: 'xterm-256color'},
The same logic applies to tmux and screen, which act like terminal emulators.
That snippet is a useless hack:
if &term =~ '256color'
" disable Background Color Erase (BCE) so that color schemes
" render properly when inside 256-color tmux and GNU screen.
set t_ut=
endif
Here are screenshots showing a perfectly working 256color-ready Vim colorscheme in Hyper.app in different scenarios, without any hack:
Below: Vim, in Hyper.app.
Below: Vim, in tmux, in Hyper.app.
I didn't bother changing Hyper.app's theme because I don't intend to use it after this answer but you hopefully get the idea.
From there, you can:
look up your colorscheme's background color and apply it to your terminal emulator's theme in ~/.hyper.js
in order to make that ugly padding more palatable,
completely remove Vim's background in order to use your terminal emulator's with something like:
function! MyHighlights() abort
highlight Normal ctermbg=NONE
highlight NonText ctermbg=NONE
highlight EndOfBuffer ctermbg=NONE
endfunction
augroup MyColors
autocmd!
autocmd ColorScheme * call MyHighlights()
augroup END
colorscheme foobar
Upvotes: 3