Search This Blog

Sunday, April 29, 2012

Colorizing Vim: How To Change Color Schemes in Vim

Colorizing Vim

Note: It is recommended (but not required) that you download VimConf, the vim customization we use at IWS: simply follow the directions under Setup on the GitHub page.

Also, if you're on Mac OSX, you will want to use iTerm2 if you don't already, as it supports 256 colors and provides improved functionality over the native Terminal app.

Changing your vim colors is pretty easy, particularly if all you are doing is installing pre-packaged color schemes.

First, navigate to the .vim subdirectory:
# with VimConf
cd ~/VimConf/.vim

# without VimConf
cd ~/.vim

Then check and see if you have a colors directory:

If not, make one...
mkdir colors

then switch into it...
cd colors

Google Code's Vim Color Scheme Test has screen shots and links for 428 different vim schemes. Under the heading Browse By File Type at the bottom of the page, select the language you'd like to see the vim screen shots in. This will take you to the page of screen shots, which take a while to load, as there are 428 schemes in 428 iframes. (Smiles.)

Above each screen shot is the name of the scheme, which doubles as a direct link to the scheme's source file. Just right click the scheme's name, then select Copy Link Address (in Chrome) or Copy Link Location (in Firefox) from the context menu.

Jellybeans color scheme

Once copied, you can use wget + paste to park the file directly in your colors directory without further modification. For example, I selected the following schemes, all of which are compatible with 256 colors:*


Finally, to actually use a color scheme you downloaded, open your vimrc file...
# with VimConf
vim ~/VimConf/.vimrc_custom

# without
vim ~/.vimrc

...and add colorscheme, a space, and the name of the file (minus the extension). Using jellybeans.vim as the example, it would look like so:

colorscheme jellybeans

Then save your file, and...


Related posts: Featuring "Vim and Vi Tips: Essential Vim and Vi Editor Skills, 2nd ed."

* I mention 256 colors for a reason: not all of the featured schemes render correctly (at least without disabling your 256 color support). Many offer a "256" version, however, as seen in the sample links above.

A second thing to note is that if you load a scheme and get weird load errors, that usually is because the file was saved on a Windows machine and the line endings are bonked (Unix/Linux uses \n, Mac \r, and Windows \r\n).

There are probably better solutions, but my approach was to...
cat affected_file.vim

copy the readout in my terminal, empty the file with...
> affected_file.vim

then open the now empty file in vim...
vim affected_file.vim

make sure that I'm in paste mode...
# with VimConf

# without
:set nonumber

go into insert mode

and manually paste the contents back in.