Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to get 256 color theme files to work with VIM under xterm.

This is peaksea how it looks for me:

enter image description here

How it should look: how it should look

I've tried following the tips on the wiki page to no avail.

set t_Co=256 works fine but

set t_AB=^[[48;5;%dm
set t_AF=^[[38;5;%dm

results in the escape sequences being displayed on the terminal:

EDIT: Mikel was right, I needed to type Ctrl+v+Esc to input the ^[ properly. However, that has not fixed my problem.

enter image description here

So what other changes can I try to make this work?

Additional info

$ uname -a
Linux xxxxxxx 3.4.7-1-ARCH #1 SMP PREEMPT Sun Jul 29 22:02:56 CEST 2012 x86_64 GNU/Linux

-

$ xterm -version 
XTerm(281)

-

$ vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Jul 13 2012 05:24:27)
Included patches: 1-600
Compiled by ArchLinux
Big version with GTK2 GUI.  Features included (+) or not (-):
+arabic +autocmd +balloon_eval +browse ++builtin_terms +byte_offset +cindent 
+clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments 
+conceal +cryptv +cscope +cursorbind +cursorshape +dialog_con_gui +diff 
+digraphs +dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi 
+file_in_path +find_in_path +float +folding -footer +fork() +gettext 
-hangul_input +iconv +insert_expand +jumplist +keymap +langmap +libcall 
+linebreak +lispindent +listcmds +localmap +lua +menu +mksession +modify_fname 
+mouse +mouseshape +mouse_dec +mouse_gpm -mouse_jsbterm +mouse_netterm 
-mouse_sysmouse +mouse_xterm +mouse_urxvt +multi_byte +multi_lang -mzscheme 
+netbeans_intg +path_extra +perl +persistent_undo +postscript +printer -profile
 +python -python3 +quickfix +reltime +rightleft +ruby +scrollbind +signs 
+smartindent -sniff +startuptime +statusline -sun_workshop +syntax +tag_binary 
+tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title
 +toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo 
+vreplace +wildignore +wildmenu +windows +writebackup +X11 -xfontset +xim 
+xsmp_interact +xterm_clipboard -xterm_save 
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "/etc/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng15   -I/usr/local/include  -march=x86-64 -mtune=generic -pipe -fstack-protector --param=ssp-buffer-size=4  -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -L. -Wl,-O1,--sort-common,--as-needed,-z,relro,--hash-style=gnu -rdynamic -Wl,-export-dynamic  -Wl,-E -Wl,-rpath,/usr/lib/perl5/core_perl/CORE  -Wl,-O1,--sort-common,--as-needed,-z,relro -L/usr/local/lib -Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0   -lSM -lICE -lXt -lX11 -lXdmcp -lSM -lICE -lm -lncurses -lnsl   -lacl -lattr -lgpm -ldl  -L/usr/lib -llua  -Wl,-E -Wl,-rpath,/usr/lib/perl5/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,--hash-style=gnu -fstack-protector -L/usr/local/lib  -L/usr/lib/perl5/core_perl/CORE -lperl -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc -L/usr/lib/python2.7/config -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic   -lruby -lpthread -lrt -ldl -lcrypt -lm  -L/usr/lib   

-

$ ls -l /usr/share/terminfo/x/xterm-256color 
-rw-r--r-- 1 root root 3336 Feb  8  2012 /usr/share/terminfo/x/xterm-256color

.vimrc

set t_Co=256

.Xdefault

!--------------------- XTERM ------------------------
xterm*dynamicColors:    true
xterm*background:       black
xterm*foreground:        #BBBBBB
xterm*utf8:             2
xterm*eightBitInput:    true
xterm*saveLines:        32767
xterm*scrollTtyKeypress:       true
xterm*scrollTtyOutput:  false
xterm*scrollBar:        false
xterm*loginShell:       true
xterm*faceName:         xft:Dejavu Sans Mono:size=10
xterm*jumpScroll:       true
xterm*multiScroll:      true
xterm*toolBar:          false
xterm*geometry:         100x30

EDIT: Attempted solutions

I already installed rxvt-unicode and was using that previously. However I had the same problem. Here is a side by side comparison of the two. On the left is xterm and on the right is urxvt. The file open is the .Xdefaults which shows the settings for urxvt one of which might be the problem?

xterm left urxvt right

I also ran the color test script with seemingly positive output. Top is xterm bottom is urxvt. top xterm bottom urxvt

$ echo $TERM
xterm-256color

Workaround solution

I'm now using CSApprox and it seems to work well enough. What I'm still confused about is why the theme doesnt work even though it has the appropriate console color settings defined. Perhaps it has something to do with the way vim considers itself. It was installed as a part of the gvim package so it could be ignoring the cterm settings.

EDIT: And now everything seems to be fine..

Strangely after installing CSApprox then removing it, everything seems to work as it should. Just downloaded another colorscheme and it loaded perfectly even without the CSApprox module running. I'm not a particularly big fan of this "magically it works" so I'll test it out on a VM with a fresh install and get back to you guys.

share|improve this question
    
What is your $TERM? Does vim know that it can use 256 colours? –  Richard Hum Aug 9 '12 at 21:14
1  
xterm is fairly problematic with UTF8 and colors and such. Have you considered using urxvt and saving yourself the hastle? (pacman -S rxvt-unicode). –  Caleb Aug 9 '12 at 21:41
1  
How did you type ^[? You need to do it using Ctrl+V+Esc. –  Mikel Aug 9 '12 at 22:33
    
@Mikel you were right about that but it seems to have not made a difference –  jmathew Aug 10 '12 at 16:13
    
@Caleb What problems do you mean? I actually switched from rxvt to xterm for better UTF-8 support and 256 colors works in both for me. I use TERM=screen-256color due to tmux though, but things also work with xterm-256color outside tmux. –  jw013 Aug 10 '12 at 17:33

3 Answers 3

try putting:

export TERM=xterm-256color

in your bashrc.

That should fix it...

share|improve this answer
1  
Exporting a $TERM value in your .bashrc rarely "fixes" anything; it is more likely to result in other unintended problems... –  jasonwryan Oct 7 '12 at 3:07

It's not only that your terminal should support 256 colors, the theme in vim will refer to the colors in your .Xdefaults/.Xresources. To fix that, you should use the same colors as the author of the theme or use gvim instead.

Peeking at the code I can see that it supports gvim properly, that's why using CSAprox works, as it take gvim color codes in HEX (e.g.:#123ABC) and translate them to your terminal colors, I think.

Example

Vim in console mode will take the colors from:

hi Normal ctermfg=16 ctermbg=254

while in graphic mode:

hi Normal guifg=#d0d0d0 guibg=#202020

So, if you installed some kind of "theme" for your terminal colors it would affect the colors you obtain in Vim. Also, double check that you have

set background=dark

in your .vimrc

share|improve this answer
    
Yep I get that cterm is what it uses when in console. The thing is I have no .Xresources file and nothing in my .Xdefaults that sets color other thmaybe an foreground and background. None of the colors are redefined. The only thing I could imagine is if the author had an .Xdefaults/.Xresources defined that differed from the defaults. But it seems that every 256 color termial theme I use varies significantly from what they're supposed to look like. Is there some other file that sets colors I'm missing? –  jmathew Aug 13 '12 at 15:39
    
I think that if we speak about X11, .Xdefaults and .Xresources are the only files involved (been the former deprecated in Archlinux systems). Of course, the default terminal colors have to live in some place and may be different given various linux distributions. Also, we can't forget that terminal emulators like Gnome Terminal can have custom colors or use the system's, as we can't know for sure if the creator of the theme used custom colors or not, though it's very plausible. Any freak that, like me, have ever made a vim theme, sure has their terminal colors customized. –  Alex Aug 15 '12 at 16:02

Caleb is right in his comment. xterm is fairly old and you should consider switching to urxvt -- at least the 256 and utf-8 enabled version, refer to your package manager to install the right one.

I have an identical set up to yours -- awesome WM, vim, urxvt, tmux/screen -- and they all work well with 256 colours and utf-8. I have set TERM to xterm-256color in case you need to set this manually.

Hum... After your edit, can you check if the vim colour theme is properly defined for terminals?

share|improve this answer
    
not sure what you mean exactly. peaksea.vim uses ctermfg/ctermbg but it does have gui functions defined as well. Could that interfere? –  jmathew Aug 10 '12 at 21:52
    
Could you try with a different colour scheme? I am not expecting this to make a large difference but you never know. The other thing I can think of is to re-compile vim from source forcing 256 colour by default. Maybe the package in arch is strange... –  Sardathrion Aug 13 '12 at 6:47

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.