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.
You can change color schemes at anytime in vi by typing colorscheme followed by a space and the name of the color scheme. For more color schemes, you can browse this library on the vim website. You can enable or disable colors by simply typing "syntax on" or "syntax off" in vi.
The default Vim color scheme in a light terminal is peachpuff . If you use a dark terminal, the initial color scheme is ron .
Some color schemes are already installed on your system. You can find those color schemes in the /usr/share/vim/vim*/colors directory as . vim extension.
You've got several options.
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.
See these topics for more info:
:help has()
:help termcap
:help termcap-colors
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With