I get no syntax highlighting with less or more. Is there a way to get syntax…
- User
I get no syntax highlighting with
lessormore. Is there a way to get syntax highlighting with these commands? - Assistant
Yes, you can get syntax highlighting in
lessandmoreby using a combination of other tools. For syntax highlighting, you can use a program likesource-highlightorpygmentize. Here's how to set it up withless:- 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-highlightFor
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- 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 ~/.bashrcFor
pygmentize:echo "export LESSOPEN='| pygmentize -f terminal256 -O style=native -g %s'" >> ~/.bashrc echo "export LESS=' -R'" >> ~/.bashrc source ~/.bashrcNow, when you use
lessto open files, you should see syntax highlighting. Unfortunately,moredoesn't support the same level of customization asless, and you cannot pipe the highlighted output to it. It's recommended to uselessfor this purpose.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.