Muffinresearch Labs by Stuart Colville

Vim: Setting the colorscheme Doesn’t Work | 5 Comments

Posted in Linux/Unix on 28th April 2009, 9:29 pm by

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.

Post Tools

  • http://intranation.com Bradley Wright

    You can also fork the display logic in your .vimrc like so:

    if has('gui_running')
    colorscheme ir_black
    else
    colorscheme desert
    end

  • http://muffinresearch.co.uk Stuart Colville

    @Bradley Wright: nice tip

  • http://intranation.com Bradley Wright

    To be clear, “gui_running” is set by GVim, so that clause will never be true in the CLI version.

  • Jim Klo

    Actually, Bradley – gvim is just vim with gui extensions compiled in … the gui_running flag is honored AFAIK for all versions of VIM regardless

  • http://muffinresearch.co.uk Stuart Colville

    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.

GNU screen: open tab in current working directory|(1)

A nice trick for having screen open a new tab in the same directory as the one you’re currently in. To use it add it to your .screenrc

# Open new window in current dir.
bind c stuff "screen -X chdir \$PWD;screen^M"
bind ^c stuff "screen -X chdir \$PWD;screen^M"

Hat tip: mteckert on SuperUser.com

Ubuntu: add-apt-repository: command not found|(3)

When you’re using a minimal Ubuntu install if you find the ‘add-apt-repository’ command is missing (it’s useful for adding PPAs and other repositories), then simply run:

sudo apt-get install python-software-properties

Photos on Flickr

© Copyright 2004-12 Stuart Colville, all rights reserved. May contain traces of Muffin. Powered by WordPress. Hosting by Slicehost.com This page was baked in 0.508s.