Tuesday 21 November 2017

How to syntax highlight via Less


is there a way to syntax highlight a file I see in Less?


actually I'm using this command to open an xml file (and sometimes a series of them)


less htmleditors/htmleditors_config.xml

or


less [multiple files]

I'd like to stay in Less (to learn that program better and to use my knowledge of :n and :p for next/previous navigation)


But it also want some kind of basic syntax highlighting – at least show the comments differently. Do you know any way to do it?



Answer



You can use GNU's source-highlight, as shown here (path may differ, see below):


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

As of Debian Stretch and Fedora 25, package names and script paths differ




  • Debian:


    sudo apt install libsource-highlight-common source-highlight
    dpkg -L libsource-highlight-common | grep lesspipe
    # /usr/share/source-highlight/src-hilite-lesspipe.sh


  • Fedora:


    sudo dnf install source-highlight
    rpm -ql source-highlight | grep lesspipe
    # /usr/bin/source-highlight/src-hilite-lesspipe.sh


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...