Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a lovely Vim colorscheme (xoria256) and it looks brilliant in GVim, but when I use normal vim in Terminal, the colorscheme is only partially supported -- for example, the default semi-transparent aubergine background color is used. How do I make Terminal faithfully render my Vim colorscheme?

share|improve this question
3  
Even the default color scheme looks better with 256 colors. If it wasn't for your question, I'd have never found it out. This should be the default. –  Mihai Capotă Nov 25 '10 at 16:32
add comment

5 Answers 5

up vote 42 down vote accepted

GNOME Terminal supports 256 colors, but doesn't advertise its support. You can override vim's autodetection by putting the following:

if $COLORTERM == 'gnome-terminal'
  set t_Co=256
endif

in your ~/.vimrc.

Note: if you use GNU screen, it will happily eat those 256-color codes and convert them to basic 16 colors. A better fix is to change TERM to xterm-256color before launching screen/vim.

share|improve this answer
1  
This didn't work, my terminal is still aubergine! –  David Siegel Jul 29 '10 at 11:08
    
What can I say -- it works for me when I do :set t_Co=256 | colorscheme xoria256. –  Marius Gedminas Jul 30 '10 at 11:48
1  
You could test for the presence of gnome-terminal in your vimrc, then set the t_Co variable appropriately. e.g.: if $COLORTERM == 'gnome-terminal' ` set t_Co = 256` endif (I'm not sure how to add multi-line blocks of code in comments, so add newlines before and after the set statement) –  Matt Aug 1 '10 at 9:47
3  
Better to use gnome-256color for gnome-terminal and screen-256color for screen. –  graywh Mar 2 '11 at 20:49
3  
@trusktr google up CSApprox and CSExact vim extensions. –  Marius Gedminas Apr 25 '13 at 13:14
show 5 more comments

A more general solution is to install the term type "xterm-256color". In 10.04 I think it's installed by default. Previously you needed to install "ncurses-term" to get it.

Then set the term type in .bashrc with something like the following:

if [ -n "$DISPLAY" -a "$TERM" == "xterm" ]; then
    export TERM=xterm-256color
fi

If you'd prefer to only have the 256 colour capability for certain programs (perhaps it confuses some others) use instead:

TERM=xterm-256color myprogram

and perhaps set that as an alias for the program.

Then check your terminal colour capabilities with:

$ tput colors
256

You still may need the vim setting above to have vim recognise it. Most applications will recognise the 256 colours automatically (if they can use them).

Emacs also has colour themes that are much better with 256 colours. To check if it 256-colour capable run:

M-x list-colors-display

256colors.pl is Perl script that will display all the colours in your terminal.

share|improve this answer
1  
Actually, gnome-256color is more correct for gnome-terminal. –  graywh Mar 2 '11 at 20:48
    
will it work in zsh, i don't use bash? –  Vinit Sep 20 '12 at 13:56
2  
Dave, I am not 100% sure if it is correct but here is a oneliner version of your command: [[ -n "$DISPLAY" && "$TERM" = "xterm" ]] && export TERM=xterm-256color. Please verify and feel free to add it to the post. –  JJD Jan 21 '13 at 21:06
    
@JJD Should work, but you can always use ; to make everthing a one-liner. –  queueoverflow Sep 16 '13 at 16:31
1  
@dave-jennings The link to the script is broken. –  queueoverflow Sep 16 '13 at 16:56
add comment

Just include the line below into your $HOME/.bashrc (preferably in the last line of the file):

export TERM="xterm-256color"

And save it. After, restart your gnome-terminal. This change will be available not only in vim, but for all your terminal applications.

To check if it works, run this little script:

#!/usr/bin/env python
# Copyright (C) 2006 by Johannes Zellner, <johannes@zellner.org>
# modified by mac@calmar.ws to fit my output needs
# modified by crncosta@carloscosta.org to fit my output needs

import sys
import os

def echo(msg):
    os.system('echo -n "' + str(msg) + '"')

def out(n):
    os.system("tput setab " + str(n) + "; echo -n " + ("\"% 4d\"" % n))
    os.system("tput setab 0")

# normal colors 1 - 16
os.system("tput setaf 16")
for n in range(8):
    out(n)
echo("\n")
for n in range(8, 16):
    out(n)

echo("\n")
echo("\n")

y=16
while y < 231:
    for z in range(0,6):
        out(y)
        y += 1

    echo("\n")


echo("\n")

for n in range(232, 256):
    out(n)
    if n == 237 or n == 243 or n == 249:
        echo("\n")

echo("\n")
os.system("tput setaf 7")
os.system("tput setab 0")

Thereafter, you will see something like the following (depends on your gnome-terminal theme):

terminal

share|improve this answer
3  
The pastebin you provided for the script is broken. –  dZkF9RWJT6wN8ux Sep 1 '13 at 12:37
    
Works like a charm, thanks! –  user10962 Oct 18 '13 at 11:45
add comment

Well, you can always configure Gvim to make it look like Vim. You just have to create a ~/.gvimrc file and paste in it these customisation tricks:

set guioptions-=r  " no scrollbar on the right
set guioptions-=l  " no scrollbar on the left
set guioptions-=m  " no menu
set guioptions-=T  " no toolbar

I don't think this solves your problem, but who knows ;-)

share|improve this answer
add comment

I made a separate profile for Vim which uses a solid, opaque color in the background. I just manually switch to it whenever I use Vim. Not sure whether or not there's a better method. I'd like to think so.

share|improve this answer
2  
You can use if has("gui_running") in your vimrc to set gui specific options. –  Matt Aug 1 '10 at 9:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.