Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a variant of cat that outputs syntax-highlighted lines of code when used on a source file?

An idea: maybe vi[m] or another editor can be asked to dump the syntax-highlighted contents of said files to stdout and exit immediately?

share|improve this question
up vote 34 down vote accepted

Passing the file through pygmentize-f terminal will attempt to detect the type from the filename and highlight it appropriately.

share|improve this answer
Is that the Star Trek: Deep Space Nine font in their logo? If it is that's awesome. – amphetamachine Aug 26 '11 at 3:57
Available as package python-pygments on Debian. – enzotib Aug 26 '11 at 7:57
I found alias pcat="pygmentize -f terminal256 -O style=native -g" to be a nice solution – Mikael Öhman Dec 26 '12 at 7:51
also available via pip install pygments – craigb Nov 8 '13 at 20:59
Actually it must be cat code.extension | pygmentize -f terminal -l extension. – fiatjaf Apr 16 '15 at 21:34

The Source-highlight package is shipped with the esc.outlang output language definition, which highlights with ANSI escape sequences.

A handy wrapper src-hilite-lesspipe.sh is also included in the package, so displaying highlighted output in the terminal is just src-hilite-lesspipe.sh source.file.

Actually src-hilite-lesspipe.sh's primary reason is to help automating the use of source-highlight with less. You just set:

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

Then any less source.file will show highlighted source code. (Code in unknown language will pass through unaltered. Highlighting will be also skipped in case of redirected content, like less < source.file.)

share|improve this answer
Nice, thank you for taking the time to write up this answer – Paolo Nov 5 '11 at 7:39

I use vimcat.


vimcat example

It looks good enough for me.

share|improve this answer

Highlight is simple to use and faster than pygmentize

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.