Syntax highlighting

Now I use most as my pager. Although it does have useful syntax highlighting for man pages, it lacks the color syntax highlighting for anything else (I'm specifically looking for diff / C ++).

Meanwhile, pygments is a great program. I can easily draw colored output with it:

 # ./pygmentize -f console256 ${file} hg diff | ./pygmentize -f console256 -l diff 

Now I would like to be able to display output, so I just use:

 # ./pygmentize -f console256 ${file} | most hg diff | ./pygmentize -f console256 -l diff | most 

At this point, most uploads all the color management symbols to my screen as follows:

 ^[[38;5;28;01mclass^[[39;00m ^[[38;5;21;01mheap_allocator^[[39;00m { ^[[38;5;28;01mpublic^[[39;00m^[[38;5;241m:^[[39m 

This, of course, is unreadable. I looked at the man page for most , but I could not find any options "Hey, show these control characters as colors instead of printing them." less has the same garbage behavior as most , but more shows colors perfectly, with obvious limitations on more .

Is there a pager that supports syntax highlighting or some crazy combination of parameters and programs that I can combine to make this work? Ultimately, I would like to get the difference and the logs from Mercurial to be highlighted, so maybe there is a shortcut ...

+9
source share
5 answers

less -R displays ANSI as-is color sequences (instead of expanding carriage notation). This will make syntax highlighting!

You can also create an environment variable LESS=-R to do this by default. Similarly for other options; see man less .

+7
source

Can I offer vimpager ?

Firstly, recent vim distributions (I believe 6.0 and above) come with a pager-esque-mode script. It is quite simple and functional and works similarly to less . Try: vim '+help less' +only .

However, even better, however, Rafael Kitover wrote a much more reliable and powerful script called vimpager . It is available on GitHub (or vimscripts ). If you are on OS X and using Homebrew, it is as simple as brew install vimpager .

At this point, you can simply set $PAGER=vimpager or even alias less=vimpager . It works great.

enter image description here

+9
source

You can try using jed. Yes, this is a text editor, not a pager, but it is quite lightweight and the standard installation contains excellent colors for a wide variety of file types and languages.

+2
source

Jed has syntax highlighting modes for different languages, similar to emacs. For example, if you submitted program C to it, you can enable the selection by pressing " ESC ", then " x ", then typing " c-mode . If it is a php program, change the last part to php-mode and so on ...

+1
source
-one
source

All Articles