Last Updated: February 25, 2016
·
1.108K
· ramynasr

Unix: Syntax Highlighting for "less"

All you need is: pygmentize ( python-pygments package ) and two lines in your "~/.bashrc"

Install Pygmentize:

sudo apt-get install python-pygments

Make "less" use it by editing "~/.bashrc" and adding these to the end:

export LESS='-R'
export LESSOPEN='|pygmentize -g %s'

The first line is to make sure that ANSI color escape sequences are output in raw form when using "less".

The second line is to allow pygmentize to preprocess the content before being passed on to "less" and "-g" flag will ask pygmentize to decide which syntax to use based on file content

Save the file then run this to start using it right away:

source ~/.bashrc