Weekend Project: Take Control of Vim’s Color Scheme

6358

Vim’s syntax highlighting and color schemes can be a blessing, or a curse, depending on how they’re configured. If you’re a Vim user, let’s take a little time to explore how you can make the most of Vim’s color schemes.

Figure 1One of the things that I love about Vim is syntax highlighting. I spend a lot of time working with HTML, for instance, and the syntax highlighting makes it much easier to spot errors. However, there’s times when the default Vim colors and the default terminal colors don’t play well with one another.

Consider Figure 1, which shows Vim’s default highlighting with the default colors in Xfce’s Terminal Emulator. Ouch. The comments are in a dark blue and the background is black. You can sort of read it, but just barely.

So what we’ll cover here is how to switch between Vim’s native color schemes, and how to modify color schemes.

Installing Vim Full

Before we get started, you’ll need to make sure that you install the full Vim package rather than the vim-tiny that many distributions ship by default. The reason that many distributions ship a smaller Vim package is that the vim-tiny package has enough of Vim for vi-compatibility for system administration (if necessary), but it saves space for the users who aren’t going to be editing with Vim all the time.

Odds are, if you’re using Vim regularly enough to care about the color schemes, you’ve done this already. If you’re on Ubuntu, Linux Mint, etc. then you can grab the proper Vim package with sudo apt-get install vim.

Changing Vim Colors

Before we go trying to edit color schemes, let’s just try some of Vim’s default schemes. You may not know this, but you can rotate through a bunch of default schemes using the :color command. Make sure you’re out of insert mode (hit Esc) and then type the :color command but hit the Tab button instead of Enter.

You should see :color blue. If you hit Tab again, you should see :color darkblue. Find a color you think might work for you and hit Enter. Boom! You’ve got a whole new color scheme.

For the record, I find that the “elflord” color scheme works pretty well in a dark terminal. If your terminal is set to a white background, I like the default scheme or “evening” scheme. (The evening scheme sets a dark background anyway, though.)

Where Colors Live

On Linux Mint, Debian, etc. you’ll find the color schemes under /usr/share/vim/vimNN/colors. (Where NN is the version number of Vim, like vim72 or whatever.) But you can also store new color schemes under ~/.vim/colors. So if you find something like the Wombat color scheme you can plop that in.

You might also want to take a look at the Vivify tool, which helps you modify color schemes and see the effects. Then you can download the file and create your own scheme.vim.

Now, if you don’t want to be setting the color scheme every single time you open Vim, you just need to add this to your ~/.vimrc:

colorscheme oceandeep

It’s just that easy.

If you want to create your own color scheme, I recommend using something like Vivify. The actual color scheme files can be very tedious to edit.