MERM MERM - 2 months ago 20
Markdown Question

Markdown syntax coloring for less (pager)

When I use vim to edit a markdown file I have nice syntax coloring (via vim-markdown and vim-markdown-preview plug-ins).

I would like to have this same syntax coloring when I am using less (pager) to view a file. Is there a way to get less to do this syntax coloring? or is there another pager that has this functionality?

Answer

less itself doesn't support syntax highlighting, but you could use GNU-source-highlight which does.

First, you'd need to install it. E.g., on RHEL/Centos/Fedora (as root):

$ yum install source-highlight

On Debian/Ubuntu

$ apt-get source-highlight

Then configure your pager to use it:

$ export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s"
$ export LESS=" -R"

Now, it should just replace less:

$ less README.md # pager with syntax highlighting
Comments