GNU screen changes vim syntax highlighting colors

I am trying to use vim inside a GNU screen session, but whenever I open vim inside screen the syntax highlighting uses completely different colors when compared to when I open vim outside GNU screen.

Why does vim change its syntax highlighting colors when I open it inside screen and how do I fix it?

Note: I am using spf13-vim in iTerm2 (OS X).

Edit: these two images show the difference when using vim in the normal bash and when using it inside screen:

  • Normal: Normal vim

  • Inside screen: vim inside screen


Solution 1:

I had similar symptoms, except that it happened for all programs not just vim. The resolution for me was to install a newer version of screen (I was using GNU screen as the backend for byobu.) I installed screen using Macports "port install screen" but I assume any method would suffice.

On my system, /usr/bin/screen --version reported 4.00.03 (FAU) 23-Oct-06. But the new screen reports 4.02.01 (GNU) 28-Apr-14. I cannot confirm whether the version upgrade was the key step, or whether the Macports screen is somehow configured differently.

Solution 2:

I'd look at TERM environment variable. When you run screen, it should be screen-256color. So, try running this command:

$ TERM=screen-256color vim

If that does help, then you probably should change your screen settings in order to make it set correct TERM for you automatically. (I'm not sure about screen configuration, I use tmux and I had similar issues that were solved by setting correct TERM)

Solution 3:

Simple workaround that worked for me (even when editing ~/.screenrc did not), based on the Dmitry Frank proposal :

alias screen='TERM=xterm-256color screen'

I added it to ~/.bashrc to make it permanent for my user.