Skip to content
The Chat Archive
gpt-4-0314· OpenAI Arena Human Preference 55K

I get no syntax highlighting with less or more. Is there a way to get syntax…

  1. User

    I get no syntax highlighting with less or more. Is there a way to get syntax highlighting with these commands?

  2. Assistant

    Yes, you can get syntax highlighting in less and more by using a combination of other tools. For syntax highlighting, you can use a program like source-highlight or pygmentize. Here's how to set it up with less:

    1. Install the syntax highlighting tool:

    For source-highlight:

    • On Debian/Ubuntu based systems:
    sudo apt-get install source-highlight
    
    • On RedHat/Fedora based systems:
    sudo yum install source-highlight
    

    For pygmentize:

    • Install Python pip:
    sudo apt-get install python3-pip   # Debian/Ubuntu
    sudo yum install python3-pip       # RedHat/Fedora
    
    • Install Pygments:
    pip3 install --user Pygments
    
    1. Set up an environment variable to use the syntax highlighting tool with less:

    For source-highlight:

    echo "export LESSOPEN='| /usr/share/source-highlight/src-hilite-lesspipe.sh %s'" >> ~/.bashrc
    echo "export LESS=' -R'" >> ~/.bashrc
    source ~/.bashrc
    

    For pygmentize:

    echo "export LESSOPEN='| pygmentize -f terminal256 -O style=native -g %s'" >> ~/.bashrc
    echo "export LESS=' -R'" >> ~/.bashrc
    source ~/.bashrc
    

    Now, when you use less to open files, you should see syntax highlighting. Unfortunately, more doesn't support the same level of customization as less, and you cannot pipe the highlighted output to it. It's recommended to use less for this purpose.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.