How to enable syntax highlighting in less


If you want syntax highlighting in less, you must install gnu source highlight software first:

In Debian based distributions you can install with:

sudo apt-get install source-highlight

When you have source-highlight package installed, you just need to set two environment variables as below:

export LESSOPEN="| /usr/share/source-highlight/ %s"
export LESS=' -R '

You should add this lines into ~/.bashrc or ~/.profile which is executed in every login.

Here is an example output with less: