Vim: Setting the colorscheme Doesn’t Work | Comments (5)
Posted in Linux/Unix on 28th April 2009, 9:29 pm by Stuart
If you’ve found a fancy colorscheme for vim and you want to try it out, once you’ve saved the colorscheme file to ~/.vim/colors you can enable the theme with the following in a vim session’s command mode:
:colorscheme fruity
If you want the colorscheme to be permanent then you can set the name of the theme in your ~/.vimrc file with:
colorscheme fruity
However if this doesn’t work then it’s probably that your terminal doesn’t support enough colors. Fixing the amount of colors the terminal can display is fairly easy by simply exporting the TERM environment variable to use the 256 color xterm. (Sadly this is not possible on OSX’s leopard terminal as it only supports 16 colors though apparently iTerm does have 256 color support)
export TERM=xterm-256color
An alternative to this is to start vim with the terminal switch set to xterm-256color e.g:
vim -T xterm-256color
Once this is done the colorschemes should work just fine.
Simplying the colors used by gvim themes
Another issue that you can hit is when trying to use a gvim (gui version) theme in vim it may specify colors that don’t fit within the range your terminal is capable of displaying. CSApprox is a plugin which converts the colors in gvim themes to the closest color that will work with your term see http://www.vim.org/scripts/script.php?script_id=2390 for more info.

You can also fork the display logic in your
.vimrclike so:if has('gui_running')colorscheme ir_blackelsecolorscheme desertend@Bradley Wright: nice tip
To be clear, “gui_running” is set by GVim, so that clause will never be true in the CLI version.
Actually, Bradley – gvim is just vim with gui extensions compiled in … the gui_running flag is honored AFAIK for all versions of VIM regardless
If you’re finding you don’t have xterm-256color on your machine I found that installation of the ncurses-term package provided it on Hardy for example.