Hints on creating 256-colour themes for vim

Most existing vim colour themes are designed for the graphical version of vim, gvim. They don't work properly at all if you are running vim in a terminal, and there are very few themes available for vim in terminal-mode. You are pretty much obliged to make your own if one of the small number of available ones doesn't suit. Here's a list of hints and tips that I discovered in the process of creating one:

  • If your shell's setting for $TERM is xterm you won't get colour support. It needs to be xtermc or you need to add a set term=xtermc in your .vimrc.
  • Even with the terminal type set you may not get 256 colours if you are using gnome-terminal. To fix that, put set t_Co=256 in your .vimrc.
  • In vim, type :help highlight to get instructions on how to specify colours in vim.
  • To make the process of authoring a colour theme easier, install the Mkcolorscheme.vim script in your vim plugin directory, uncommenting the four commands at the top of the file. Read the instructions in the plugin, they give you hints on how to identify the colours currently being used by syntax elements.
  • Open a new subwindow in vim and type :so $VIMRUNTIME/syntax/hitest.vim. That will display a table of the current settings, which will be updated as you interactively change colours.
  • Open this colour chart in your browser, it gives you the colour numbers you'll need to set the colours.
  • Open up a source file of the type that you want to set the syntax colouring for, put the cursor over an element and use the :GetSyntax command to identify the element type, followed by the appropriate:highlight command to set the element colour.
  • When you are done, use the :Mkcolorscheme command to generate a set of commands to generate the colour scheme settings. Delete any lines containing cleared as they aren't valid.
  • Save the colour scheme to a file in your vim colors directory and load the scheme with a colorscheme command in your .vimrc.
Categories : Tech