I am using vim and MacVim. I have a 256-colour colorscheme which I like for my MacVim, but if I load it into regular vim, it obviously does not work (I get blinkies instead). I would like to be able to use the same vim config on all my systems, so:

Is there a way to check for palette size in .vimrc and set one of the two colorschemes accordingly? If that is not feasible, then checking for MacVim vs. vim would also be okay.

2 Answers
2

I think your best bet is to load one colorscheme in .vimrc, and another in .gvimrc (or in your case, just don't load a colorscheme in .vimrc at all). The .gvimrc colorscheme will only be loaded when you're running the GUI version of MacVim.

If you don't want to split your configuration across multiple files, you can also use a conditional like this one in .vimrc:

if has('gui_running')
colorscheme mycrazycolors
endif

Finally, if you really do want to know the number of colors available, you can check the t_Co setting:

:echo &t_Co

t_Co is empty in the GUI version of MacVim, so you'll probably still want to use a variation of the has() technique. In fact, the default .vimrc does something similar to determine when to enable syntax highlighting:

if &t_Co > 2 || has("gui_running")
syntax on
endif

For the sake of completeness, I should mention that you could also expand your colorscheme file to include reasonable settings for color terminals. This is a fair amount of work, however, and it might be easier to just switch to a terminal application that supports more colors.