Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6228305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:21:58+00:00 2026-05-24T09:21:58+00:00

I was trying to make the syntax highlighting (with 256 colors) of vim work

  • 0

I was trying to make the syntax highlighting (with 256 colors) of vim work inside screen, which is running inside gterm.

It works quite fine in the beginning. What I mean by “in the beginning” is, after I start screen, and enter vim, the colors look fine, and there are really 256 colors.

But after a while (I don’t know exactly how long) the colors automatically change back to an appearance as if there are only 8 (or 16?) colors.

For example, after this has already occurred, if I enter the command

hi Comment ctermfg=68

inside vim, the comments appear to be “pure” green; however, if I open another vim outside screen (in the same terminal), then with the same command the comments appear to be a “yellowish” green.

The following is my .screenrc settings related to color:

attrcolor b ".I"
defbce "on"
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
term xterm-256color

After running a python script to display all the colors, I find out that maybe this is a problem of screen itself, and has nothing to do with vim.

What I did is, inside the screen session with problems, this script gives 256 colors, but many of them are actually the same; however, when I start a new screen session with the same configuration, this script gives 256 colors which are distinct from each other.

Edit:

Last night I connected to my Linux computer (which is in my office and it is always on) with putty, then opened a screen session with multiple windows in it. The colors are correct last night. Then before I went to sleep I detached the screen session and closed putty.

Now in the morning when I attach that screen session in putty again, the colors crash: they appear as if there are only 8 colors.

The colors are fine outside screen (but still in putty).

Edit:

Three years later after I asked this question, today I saw a similar problem. The problem is that vim can display 256 colors outside screen, and screen can display 256 colors with a test script, but vim can’t display any color (can only display black and white) inside screen. Just as a note to myself, here is the .screenrc file I am using

hardstatus alwayslastline "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %Y-%m-%d %c"
shell "bash"
startup_message off
vbell off
altscreen on
attrcolor b ".I"
defbce "on"
termcapinfo xterm* 'is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l'
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
term screen-256color

The solution to the problem is already mentioned in the accepted answer, namely, I need to include

export TERM=xterm-256color

in .bashrc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:21:58+00:00Added an answer on May 24, 2026 at 9:21 am

    Short Answer

    Set TERM to xterm-256color in your .bashrc, and put term screen-256color in your .screenrc.

    Long Answer

    Here’s why this breaks: gnome-terminal, screen, tmux, bash, putty and vim have all been written to intelligently handle 256 colors, but you need to set things up correctly at the earliest possible point. Using termcapinfo in your .screenrc is actually a duct tape solution!

    If your TERM is set correctly, it will signal to bash that you’re in 256-color mode, which means it will play nice with screen being in 256-color mode as well.

    So, in your .bashrc, export TERM=xterm-256color. [1]

    In your .screenrc, use screen-256color for TERM instead of xterm-256color, and delete the rest of the cruft!

    In your PuTTy configuration, use putty-256color.

    You can download the termcap entry files and put them in ~/.terminfo/s and ~/.terminfo/p, if your box doesn’t have them by default.


    Footnotes

    [1] Setting TERM to xterm-256color in your .bashrc can be a little presumptuous, especially if you use the same .bashrc on multiple machines. I have found the following snippet to be fairly effective:

    case "$TERM" in
    *-256color)
        alias ssh='TERM=${TERM%-256color} ssh'
        ;;
    *)
        POTENTIAL_TERM=${TERM}-256color
        POTENTIAL_TERMINFO=${TERM:0:1}/$POTENTIAL_TERM
    
        # better to check $(toe -a | awk '{print $1}') maybe?
        BOX_TERMINFO_DIR=/usr/share/terminfo
        [[ -f $BOX_TERMINFO_DIR/$POTENTIAL_TERMINFO ]] && \
            export TERM=$POTENTIAL_TERM
    
        HOME_TERMINFO_DIR=$HOME/.terminfo
        [[ -f $HOME_TERMINFO_DIR/$POTENTIAL_TERMINFO ]] && \
            export TERM=$POTENTIAL_TERM
        ;;
    esac
    

    The alias of ssh is a defensive measure to prevent us from trying to open a 256-color terminal on a remote machine that doesn’t necessarily support it. The main block is the other half of the equation; it checks to see if the corresponding terminfo entry exists, and sets it if it does.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a TextBox with syntax highlighting (for (HTML/CSS) in VB.NET 2008.
I've created a new syntax highlighting theme and am trying to make it available
C.Vim works, as evidenced by the commands I've been using, syntax highlighting, and template.
I am trying to make syntax hightlighting and building options work for Geany, any
I am trying make long screen to vertical direction. So, I need a screen
trying to make a page which will recursively call a function until a limit
I am trying to make use of this Syntax highlighter. I have tried to
I am trying to make this IF statement work, but I can't seem to
I'm trying to make an Ajax call on all <a> elements inside the id
I am trying to make the page scroll to post which has specific id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.