Thanks very much for various info! I’ve just installed & tried them, and the results are like the following (on my old mac mini, OSX10.11, so the results may vary for newer OS). (And sorry for a very long post… please go to the last part for my summary.)
I’ve installed this via
brew install pygments then got the command
pygmentize. This command accepts a source code and outputs a colored text to standard output:
$ pygmentize test.f90 !! displays a colored code
$ pygmentize -l fortran test.f90 !! specifies "lexar" explicitly
The output itself is very nice, but one problem (for me) is that it behaves like
cat, i.e., the program exits when it reaches the end of file. So I tried a pipe like
$ pygmentize test.f90 | less # or "more"
but this displays the original code + raw ASCII texts for colors, which is not suited for human… Interestingly, piping with
cat does not have this problem and show the colored code successfully
$ pygmentize test.f90 | cat
but the command exits at the EOF… (please see below for one possible workaround).
bat was already installed via homebrew (maybe auto-installed by other packages?), I’ve tried the following:
$ bat test.f90
This displays the original code with line numbers, but for some reason it does not show any color for my .f90 code… To check, I also tried other languages (like C) and it does show color. So I’m wondering do I possibly need some setting for .f90 files? (I also checked
bat --list-languages, but it does not have f90 in the support list.)
I’ve just tried this as
vim -R test.f90, but again this does not show color for some unknown reason… Indeed, even the usual
vim test.f90 does not show color either, so I am afraid that my setting on Vim or other environment stuff may have something wrong
it does help to know how to exit vim
Thanks for the advice, and do not worry because I learned how to exit Vim before (one of the most famous questions on programming )
Even more recently, there seem to be a lot of newer approaches developed for this purpose (including the “the hardware way”).
A search for “less with syntax highlighting” turned up many links, some of which may be worth looking into.
Thanks, I will try this “again”. Indeed, more than 10(?) years ago, I searched the net for this and tried some 3rd-party tool (I forgot the name of it, though). It does show color successfully, but it behaved like
cat (i.e., the program exits at EOF)… So I gave up about it at that time. I guess I might find some newer tools that behave more like
After playing with the above commands for a while, I happened to try this combination
$ pygmentize test.f90 | bat
which worked exactly as I want!! Even the search of variable/routine name with a slash (/) key also works (like “less”). So I will make a bash command for this for convenient use. Thanks very much!