1

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.

EDIT:

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

EDIT (2):

Here are the screenshots of the same theme and how is it rendering on

  • terminal.app: enter image description here

  • hyper.app:

enter image description here

  • and the Mac vim gui (correct): enter image description here
Ishan Srivastava
  • 1,129
  • 1
  • 11
  • 29
J. Doe
  • 43
  • 2
  • 9

2 Answers2

3
  1. 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
    
  2. 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.

  3. 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
    
  4. 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.

    Vim

    Below: Vim, in tmux, in Hyper.app.

    Vim in tmux

    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.

  5. 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
      
romainl
  • 186,200
  • 21
  • 280
  • 313
  • I tried your solution, removed the `$TERM` definitions from `.bashrc` and `.zshrc`, used the `env` in hyper but I still couldn't get it right. I edited my question and added screenshots of the same theme mentioned in the question and how is it rendering on terminal.app, hyper.app and the mac vim gui and except from the gui, everything seems to follow its own thing. Would be great if you can help me debug the cause of this behaviour. – J. Doe Jul 18 '18 at 21:21
  • 1
    That turd **doesn't support 256color terminal emulators**. It is made for GUI Vim, 8/16color terminal emulators, and terminal emulators that support the new fancy "true color" feature. Path A: get yourself a proper 256color-ready colorscheme. Path B: make your terminal colors match your colorscheme. Path C: if Hyper.app supports that "true color" feature, set Vim to make use of it with `:help 'termguicolors'`. – romainl Jul 18 '18 at 21:54
  • just to be sure I went ahead and tried this http://vimcolors.com/727/simplifysimplify-light/light again and I have similar results. The GUI works fine but the background + syntax highlighting colors are still dark and muddled up, following their own will. Even after setting `set background=light` on both terminal.app and hyper.app – J. Doe Jul 19 '18 at 00:54
  • just to be on the same page, by *"that turd"* you meant my theme right? – J. Doe Jul 19 '18 at 00:59
  • tried a bunch of themes for the terminal and some of them gave me this error like http://vimcolors.com/796/Iosvkem/dark **Error detected while processing /Users/.../.vim/plugged/iosvkem/colors/Iosvkem.vim: line 11: [Iosvkem] There are not enough colors.** – J. Doe Jul 19 '18 at 01:06
  • Well you have two turds, here: Hyper.app and that colorscheme. Could you try my colorscheme romainl/apprentice? It's the one I've used for the screenshot. It works without setting anything in a freshly downloaded Hyper.app. – romainl Jul 19 '18 at 07:06
0

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:

  • In your .vimrc set your vim background to transparent:
"Overrides the color scheme background and makes it transparent      
 autocmd ColorScheme * highlight Normal ctermbg=None                                          
 autocmd ColorScheme * highlight NonText ctermbg=None
  • Change the background of your terminal to the desired background-color