You are not logged in.

#1 2009-12-15 03:04:53

Anikom15
Banned
From: United States
Registered: 2009-04-30
Posts: 836
Website

Vim: setting theme

I want to set Vim to desert256 ONLY when using it with gui terminals. How can I tell Vim to use the default with the ttys?


Personally, I'd rather be back in Hobbiton.

Offline

#2 2009-12-15 03:19:18

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: Vim: setting theme

In your vimrc, add something like

if &t_Co == 256 || &t_Co == 88
  colorscheme desert256
endif

Last edited by lolilolicon (2009-12-15 03:34:22)


This silver ladybug at line 28...

Offline

#3 2009-12-15 09:57:23

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: Vim: setting theme

I just have vim look for xterm (aren't all terminals based on this?):

if &term=="xterm"                 " use 256 color palette if available
  set t_Co=256
  colorscheme wombat256
endif

lolilolicon, what terminal is that for? ... doesn't work on Konsole in KDE.


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#4 2009-12-15 11:57:49

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: Vim: setting theme

@Gen2ly

Probably the t_Co variable is not set in Konsole, but it is set here in urxvt-256color.

:echo &t_Co "echo the value of t_Co
:set termcap "list all termcap info, where you can see if t_Co is set

'term' is not always set to "xterm" for gui terminals. For example, when you use vim inside screen or tmux, it will be set to "screen"; and in my urxvt it is by default set to rxvt-256color. (as per :echo &term)

Maybe it will work better by just testing against "linux", if the t_Co method fails on you (works for me tho, also in tty, where its value is 8).

if &term != "linux"
  colorscheme desert256
endif

But this is based on the assumption that tty always sets 'term' as "linux". This I think perhaps is wrong.
And you can also make use of the $COLORTERM variable to identify your terminal too.

So... pick whatever works for you, I'd say.

Last edited by lolilolicon (2009-12-15 12:01:43)


This silver ladybug at line 28...

Offline

#5 2009-12-15 15:02:38

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: Vim: setting theme

lolilolicon wrote:

...
Maybe it will work better by just testing against "linux", if the t_Co method fails on you (works for me tho, also in tty, where its value is 8).

if &term != "linux"
  colorscheme desert256
endif

But this is based on the assumption that tty always sets 'term' as "linux". This I think perhaps is wrong.
And you can also make use of the $COLORTERM variable to identify your terminal too.

Hmm, good thought, but as you allude to this wouldn't include the terminals that are do have a few odd number color settings (if I remember right urxvt was 192??).  I also too found it a little peculiar that "linux" was used since Linux is the kernel, thought it might have to do with an Arch setting.

Never heard of $COLORTERM before...


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#6 2009-12-15 15:45:17

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: Vim: setting theme

Gen2ly wrote:

this wouldn't include the terminals that are do have a few odd number color settings (if I remember right urxvt was 192??)

Well as long as the t_Co var is set already and correctly, you can always test it with something like ``if &t_Co >= 88'', if that theme makes sense under 88, 192, foo, bar and what-baz-so-ever.

Whatever works I'd say, again. I can't be confirmed that any of the methods mentioned will 100% work, but combining those tests together may increase your winning chance. For my tty, &t_Co is 8, &term is "linux", and $COLORTERM is not set.

It'd be really nice if someone come and post a killer tester one-liner and say, let's screw all that crap.

Last edited by lolilolicon (2009-12-15 15:45:53)


This silver ladybug at line 28...

Offline

#7 2009-12-16 08:45:02

Bralkein
Member
Registered: 2004-10-26
Posts: 354

Re: Vim: setting theme

Hi, just to throw in my idea too, it seems like $DISPLAY is always set to something (eg. :0.0) if the term is running under X. On the plain TTYs it's undefined. I tested the following code and it seems to work:

if $DISPLAY != ''
  colorscheme desert256
endif

HTH.

Offline

#8 2009-12-16 16:21:41

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: Vim: setting theme

@ Bralkein

Hmm, good thinking as any terminal program will return a $DISPLAY value and console program would not...  Ultimately lolilolicon's idea to look for $COLORTERM would be the cover-all solution (as for some instances a user might use more than one terminal that doesn't have 256 color support), but should work for most cases.


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#9 2009-12-16 23:07:08

Anikom15
Banned
From: United States
Registered: 2009-04-30
Posts: 836
Website

Re: Vim: setting theme

Thx, Bralkein's solution worked great.


Personally, I'd rather be back in Hobbiton.

Offline

#10 2009-12-17 00:18:05

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Vim: setting theme

ignore me, i need to read betters

edit: on a relatedly note, i use this...

" set 256 colors if we can
if $TERM =~ "-256color"
  set t_Co=256
  colorscheme zenburn 
endif

Last edited by brisbin33 (2009-12-17 00:28:09)

Offline

Board footer

Powered by FluxBB