Vim Colours and Syntax Highlighting

2015-07-07(Tue)

tags: Vim

photo: courtesy of @nixCraft

Vim without colours is Arnold Schwarzenegger on a motorcycle; vim with ":syntax on" is ... colourful.

Vim syntax highlighting can be fantastically garish. It is, without a doubt, very useful, but anyone can make a colour scheme and not everyone should. With that in mind, these are some I like that may look horrible to you. If my choices don't suit you, just do a google search for "best vim colors": a LOT of people have opinions about this. In fact, stop reading and go to https://code.google.com/p/vimcolorschemetest/ or http://vimcolors.com/ first to get a taste of the huge variety available.

The colour schemes below are exclusively for black or very dark backgrounds. See below for download links.

General purpose: ir_black or derivative tir_black

Debian defaults: elflord or slate (if I haven't had time to install my preferred colours)

16 Colour Terminals: wuye

Bash: black_angus, tir_black

CSS: shobogenzo

Dot/Graphviz: herald, molokai, nightsky, jellyx

HTML: nightsky, shobogenzo, tir_black, herald, jammy

Java: candy, candycode, ir_black, jammy, nightsky, oceanblack, shobogenzo!

JavaScript: nightsky

JSP: nightsky

Makefile: gardener, tir_black, ir_black

Markdown: badwolf, jellybeans, tir_black, wuye

Python: tir_black

RST: nightsky, NOT oceanblack, NOT slatedark

Vimcode: shobogenzo, jammy

XML: candy, herald, jammy, ir_black, NOT shobogenzo

YML: badwolf, black_angus, darkdevel, tir_black

Configuration

Getting 256 colours out of vim in a console can be a real PITA. Vim takes its cues from the terminal its in, and if the terminal says it only supports eight colours, vim believes it.

# add this to /etc/profile on Linux systems
if [ -e /usr/share/terminfo/x/xterm?256color ]
then
    export TERM='xterm-256color'
else
    export TERM='xterm-color'
fi
" Add this to your ~/.vimrc
if &term=="xterm-256color"
    set t_Co=256 " "terminal has 256 colors"
endif

If you're on a Mac AND using tmux, you have to go a step further:

# add to ~/.tmux.conf because tmux has trouble figuring out the number of colours
set -g default-terminal "screen-256color" # your Mac supports it