You are not logged in.

#1 2010-04-23 23:50:01

xelados
Member
Registered: 2007-06-02
Posts: 314
Website

[SOLVED] How to convince vim my terminal supports color?

Hi. I recently got a shell account from Kaitocracy on his linode machine. I noticed that my bash prompt has color, as expected, but when I copied over my vim configuration (which includes a color theme), it didn't work! After some toying around, I noticed that vim recognizes the terminal escape codes using `:hi <type> start= stop=`, but not the existing `cterm` commands in my color theme. To make things more confusing, I know my terminal (urxvt) is capable of using the cterm flags.

Also, Ctrl+L does not clear/redraw the screen as expected.

What can I do to fix these issues? Here are the configs:

~/.vimrc:

" No vi compatibility; strictly vim here.
set nocompatible

" Don't source /etc/vimrc
set noexrc

" My background is always black
set background=dark

" The mouse is helpful every now and then...
set mouse=a

" I'm a Linux user
set fileformats=unix,dos,mac

" Search while I type
set incsearch

" The blinking pisses me off
set novisualbell

" Line numbers are key to debugging
set number
set numberwidth=5

" My tabs are 4 characters long
set tabstop=4
set softtabstop=4

" Indention is also 4 characters
set shiftwidth=4

" Normally, I don't want tabs converted to spaces.
set noexpandtab

" Syntax highlighting is a staple :D
syntax on

" I want liberal use of hidden buffers, just in case.
set hidden

set laststatus=2

" filename, filetype, readonly flag, modified flag line #, column #, %age of file length, hex value of byte under cursor.
" Ex: .vimrc [vim][+] 48,22 55% hex:20
set statusline=%f\ %y%r%m\ %l,%c\ %P\ hex:%B

set noai

" I can see where tabs and line endings are
set listchars=tab:▸\ ,eol:¬

" This turns on the config above; I can turn it off with :set nolist
set list

" I want wordwrap on, coupled with sane line-breaking. This will not work when :set list is active.
set wrap
set lbr

" My color scheme is pwn
colorscheme sporkbox

filetype indent on

if has("autocmd")
    " enable filetype detection
    filetype on

    " I want to convert tabs to spaces to adhere to PEP 8.
    autocmd FileType python setlocal ts=4 sts=4 sw=4 expandtab

endif

" \l toggles invisibles
nmap <leader>l :set list!<CR>

" I like to get rid of trailing white space.
nnoremap <silent> <F5> :call <SID>StripTrailingWhitespaces()<CR>

" Fast window movement is important
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l

" Courtesy of vimcasts.org
function! <SID>StripTrailingWhitespaces()
    " Save last search and cursor position
    let _s=@/
    let l = line(".")
    let c = col(".")
    " Do the business:
    %s/\s\+$//e
    " Restore previous search history and cursor position
    let @/=_s
    call cursor(l, c)
endfunction

~/.vim/colors/sporkbox.vim:

" Color scheme "sporkbox"
" by Daniel Campbell <danny@sporkbox.us>

" Tab characters and EOLs should be dark gray so they don't stand out too much.
highlight SpecialKey ctermfg=darkgray
highlight NonText ctermfg=darkgray

" If I'm in a mode, I want to see it.
highlight ModeMsg ctermfg=green

" The current file should be obvious; the others can be faded.
highlight StatusLine ctermfg=green ctermbg=black
highlight StatusLineFC ctermfg=darkgray ctermbg=white

" Line numbers should be just-visible, not bright.
highlight LineNr ctermfg=darkgray

" Titles in Markdown
highlight Title cterm=bold ctermfg=white

" My splits should not be bright
highlight VertSplit ctermfg=black ctermbg=darkblue

highlight Comment ctermfg=darkgreen
highlight Constant ctermfg=cyan
highlight Identifier ctermfg=yellow
highlight Statement ctermfg=magenta
highlight PreProc ctermfg=lightblue
highlight Type ctermfg=blue
highlight Special ctermfg=lightblue

Remote .bashrc:

### ~/.bashrc: Sourced by all interactive bash shells on startup

# Set a fancier prompt
PS1='\[\e[32;01m\]\u\[\e[m\] \[\e[36m\]\w\[\e[m\]: '

# Turn on colors for ls and grep
alias less='less --RAW-CONTROL-CHARS'
alias ls='ls --color=auto'
alias grep='grep --color=auto'

# Set colors for ls and friends
if [ -f ~/.dir_colors ]; then
  eval `dircolors -b ~/.dir_colors`
elif [ -f /etc/dir_colors ]; then
  eval `dircolors -b /etc/dir_colors`
else eval `dircolors -b`; fi

# Compilation optimization flags
CHOST="i686-pc-linux-gnu"
MAKEFLAGS="-j2"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--hash-style=both"
CFLAGS="-march=pentium4 -O2 -pipe -fomit-frame-pointer"
FFLAGS="-march=pentium4 -O2 -pipe -fomit-frame-pointer"
CPPFLAGS="-march=pentium4 -O2 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=pentium4 -O2 -pipe -fomit-frame-pointer"

export PGHOST="private1.kiwilight.com"

export PS1 CHOST MAKEFLAGS LDFLAGS CFLAGS FFLAGS CXXFLAGS

To make matters more confusing, my vim theme works when I connect to the linode in a GNU screen session, but not when it's a straight-up terminal.

Last edited by xelados (2010-04-25 00:34:44)

Offline

#2 2010-04-24 00:06:27

Peasantoid
Member
Registered: 2009-04-26
Posts: 928
Website

Re: [SOLVED] How to convince vim my terminal supports color?

I'm guessing it has something to do with the remote machine's $TERM...?

Offline

#3 2010-04-24 00:10:26

xelados
Member
Registered: 2007-06-02
Posts: 314
Website

Re: [SOLVED] How to convince vim my terminal supports color?

Both report correctly; screen reports $TERM as "screen" and a plain urxvt reports as "rxvt-unicode"

Offline

#4 2010-04-24 01:39:31

antlechrist
Member
Registered: 2010-04-21
Posts: 26

Re: [SOLVED] How to convince vim my terminal supports color?

Hi xelados: For vim you might want:

set t_Co=256

or something similar (some other # of colors.)

HTH

Offline

#5 2010-04-24 08:45:02

xelados
Member
Registered: 2007-06-02
Posts: 314
Website

Re: [SOLVED] How to convince vim my terminal supports color?

Interesting; when I manually export $TERM as "screen", the colors show up fine despite not being inside a screen session. Why is this behavior happening? I've poured over all my user files and haven't seen anything relating to it.

Offline

#6 2010-04-24 09:05:30

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: [SOLVED] How to convince vim my terminal supports color?

Are you sure "screen" works as $TERM?
What if you export $TERM to "screen-256color" ?

As to why it works that way - read about termcap and terminfo (and see how retarded that approach is)


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#7 2010-04-24 11:28:07

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: [SOLVED] How to convince vim my terminal supports color?

Make sure you are using rxvt-unicode-256color and that your TERM is rxvt-256color outside of screen, and screen-256color inside of screen.


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#8 2010-04-24 11:46:39

xelados
Member
Registered: 2007-06-02
Posts: 314
Website

Re: [SOLVED] How to convince vim my terminal supports color?

Mr.Elendig wrote:

Make sure you are using rxvt-unicode-256color and that your TERM is rxvt-256color outside of screen, and screen-256color inside of screen.

That's the peculiarity of the problem; when I run vim in my local environment, I always get color using the `:hi <hilighttype> ctermfg=* ctermbg=*` commands. This applies inside of X through rxvt-unicode (non-256color), GNU screen, and on the plain command line in vc1. This issue seems to be related to the remote environment and/or variables not being sent through ssh.

@moljac: When I echo'd TERM inside a screen session, it returned "screen", so I don't know whether it's legit or not.

Last edited by xelados (2010-04-24 11:47:52)

Offline

#9 2010-04-24 14:50:39

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: [SOLVED] How to convince vim my terminal supports color?

Do you actually have a terminfo for rxvt-unicode on the remote machine?


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#10 2010-04-24 15:53:52

xelados
Member
Registered: 2007-06-02
Posts: 314
Website

Re: [SOLVED] How to convince vim my terminal supports color?

I don't know; how do I check?

Offline

#11 2010-04-24 16:44:39

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: [SOLVED] How to convince vim my terminal supports color?

The manual for terminfo
makes it very clear
that all you have to do is
point your file browser over here,
where here = /usr/share/terminfo/


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#12 2010-04-25 00:34:28

xelados
Member
Registered: 2007-06-02
Posts: 314
Website

Re: [SOLVED] How to convince vim my terminal supports color?

It seems that the admin of the box installed urxvt since others were having the same issue. all works fine now..

Thanks for the information; I know where to look if I have the same issue in the future. smile

Offline

Board footer

Powered by FluxBB