9

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

4
  • Try following the instructions here: robotsrule.us/vim
    – Heptite
    Aug 19, 2014 at 20:29
  • The result is the same. Actually, the instructions from that page make everything come out as ANSI escape sequences instead of colors =/ Aug 19, 2014 at 21:16
  • Did you find any way to make it work?
    – Sam
    Nov 1, 2015 at 9:02
  • No, I started using tmux and it worked flawlessly. And tmux is much better than screen so this actually was for the greater good. Nov 3, 2015 at 14:50

4 Answers 4

4

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.

2
  • 1
    This works for me too with homebrew. brew install screen
    – FelikZ
    May 21, 2015 at 20:22
  • I tried all the other suggestions (set $TERM, update .screenrc with term xterm-256color or change .bashrc). Only installing a new version of screen worked on macOS 13.3.1
    – Punkman
    May 22, 2023 at 6:15
5

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)

8
  • I already tried changing the TERM variable to the same variable that iTerm2 uses by default (xterm), but it didn't work. screen-256colordidn't work also. Aug 19, 2014 at 18:39
  • @RenatoUtsch, I've done some tests on my Linux machine so I have one more idea: if screen itself thinks that your terminal doesn't support 256 color, behavior is different. So, firstly, try running screen with this command: TERM=xterm-256color screen , and then, inside screen, run vim as follows: TERM=screen-256color vim. Aug 19, 2014 at 18:48
  • the result is the same. The highlighting didn't change from that image that I added to my question. Aug 19, 2014 at 18:55
  • Hmm, on my machine, if I run screen with TERM=xterm screen, and then TERM=screen-256color vim, colors are ugly. If I run screen so that it thinks that my terminal supports 256 colors, colors are fine. Sorry, no more exact ideas. I assume you've already seen these easy googleable links: askubuntu.com/questions/87169/using-gnu-screen-with-256-colors and robotsrule.us/vim Aug 19, 2014 at 18:58
  • 1
    My problem was different, screen itself changed some colours (e.g. custom bash prompt went from orange to red) but oddly running vim in screen did use my custom colours. So just a comment, not an answer: simply the suggested command TERM=xterm-256color screen worked for me. I couldn't find a way to add this to screen configuration file so I just aliased it, alias screen='TERM=xterm-256color screen'. Screen version 4.00.03 (FAU) 23-Oct-06 on Oracle Linux 2.6.32-431.5.1.el6.x86_64 Jul 2, 2015 at 13:19
1

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.

0

I hope it isn't too late.

Normally, on your ~/.vimrc there might be a line

colorscheme yourColorScheme

where yourColorScheme is one of the .vim color configuration file your can find in /usr/share/vim/vim80/colors/, without the .vim extension Example, I want to use /usr/share/vim/vim80/colors/blue.vim configuration file, I do

colorscheme blue

If this line isn't written in .vimrc, then vim will select a default color configuration file and that selection might be different while using screen.

I had the same problem and solve it while adding this line à the end of the file.

The only distasteful thing is that you will probably have to try all the configuration listed in /usr/share/vim/vim80/colors/ to find the one you liked (I advise you to open a terminal with your ~/.vimrc opened in to test the differents colorshemes, a second terminal where you vim a file that shows you the good syntax color you like, and a third and a third where you launch screen and vim the same file to see the new syntax color and compare)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .