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
$TERMisxtermyou won't get colour support. It needs to bextermcor you need to add aset term=xtermcin 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=256in your.vimrc. - In vim, type
:help highlightto 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
:GetSyntaxcommand to identify the element type, followed by the appropriate:highlightcommand to set the element colour. - When you are done, use the
:Mkcolorschemecommand to generate a set of commands to generate the colour scheme settings. Delete any lines containingclearedas they aren't valid. - Save the colour scheme to a file in your vim
colorsdirectory and load the scheme with acolorschemecommand in your.vimrc.
Categories : Tech