Add source code syntax highlighting for less

It is about how to get colorized less output for source code.

This howto is written with respect to Ubuntu 17.10.

1) Install source-highlight

sudo apt-get install source-highlight

2) Look for lesspipe

dpkg -L libsource-highlight-common | grep lesspipe

My one is in /usr/share/source-highlight/ folder

3) add two following lines in your .bashrc

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

Happy lessing!

Leave a Reply

Your email address will not be published. Required fields are marked *