How to syntax highlight via Less Announcing the arrival of Valued Associate #679: Cesar...

Why do early math courses focus on the cross sections of a cone and not on other 3D objects?

What makes a man succeed?

How much damage would a cupful of neutron star matter do to the Earth?

Why does it sometimes sound good to play a grace note as a lead in to a note in a melody?

How many morphisms from 1 to 1+1 can there be?

Flight departed from the gate 5 min before scheduled departure time. Refund options

What are the discoveries that have been possible with the rejection of positivism?

How did Fremen produce and carry enough thumpers to use Sandworms as de facto Ubers?

How can I set the aperture on my DSLR when it's attached to a telescope instead of a lens?

Co-worker has annoying ringtone

What to do with repeated rejections for phd position

Crossing US/Canada Border for less than 24 hours

Strange behavior of Object.defineProperty() in JavaScript

Google .dev domain strangely redirects to https

How many time has Arya actually used Needle?

Why are vacuum tubes still used in amateur radios?

Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?

AppleTVs create a chatty alternate WiFi network

Is CEO the "profession" with the most psychopaths?

Maximum summed subsequences with non-adjacent items

A term for a woman complaining about things/begging in a cute/childish way

How would a mousetrap for use in space work?

Is it possible for SQL statements to execute concurrently within a single session in SQL Server?

How to write capital alpha?



How to syntax highlight via Less



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)LESS and CSS3 syntax highlightinghaml and sass syntax highlight in smultronLESS and CSS3 syntax highlightingLESS syntax highlighting in GeanyMatch (highlight) invalid Hungarian notation variables syntaxless doesn't highlight searchSyntax highlight in SublimeText 2Notepad++ variable name syntax highlightIs it possible in vim to search for a term excluding those appearing in comments/block comments?vim syntax highlight limited to 3000 charsAuto highlight a custom syntax in cmd





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







126















is there a way to syntax highlight a file I see in Less?



actually I'm using this command to open an xml file (and sometimes a series of them)



less htmleditors/htmleditors_config.xml


or



less [multiple files]


I'd like to stay in Less (to learn that program better and to use my knowledge of :n and :p for next/previous navigation)



But it also want some kind of basic syntax highlighting – at least show the comments differently. Do you know any way to do it?










share|improve this question





























    126















    is there a way to syntax highlight a file I see in Less?



    actually I'm using this command to open an xml file (and sometimes a series of them)



    less htmleditors/htmleditors_config.xml


    or



    less [multiple files]


    I'd like to stay in Less (to learn that program better and to use my knowledge of :n and :p for next/previous navigation)



    But it also want some kind of basic syntax highlighting – at least show the comments differently. Do you know any way to do it?










    share|improve this question

























      126












      126








      126


      60






      is there a way to syntax highlight a file I see in Less?



      actually I'm using this command to open an xml file (and sometimes a series of them)



      less htmleditors/htmleditors_config.xml


      or



      less [multiple files]


      I'd like to stay in Less (to learn that program better and to use my knowledge of :n and :p for next/previous navigation)



      But it also want some kind of basic syntax highlighting – at least show the comments differently. Do you know any way to do it?










      share|improve this question














      is there a way to syntax highlight a file I see in Less?



      actually I'm using this command to open an xml file (and sometimes a series of them)



      less htmleditors/htmleditors_config.xml


      or



      less [multiple files]


      I'd like to stay in Less (to learn that program better and to use my knowledge of :n and :p for next/previous navigation)



      But it also want some kind of basic syntax highlighting – at least show the comments differently. Do you know any way to do it?







      syntax-highlighting less






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 17 '09 at 10:20









      Jesper Rønn-JensenJesper Rønn-Jensen

      2,81062128




      2,81062128






















          15 Answers
          15






          active

          oldest

          votes


















          120














          You can use GNU's source-highlight, as shown here (path may differ, see below):



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


          As of Debian Stretch and Fedora 25, package names and script paths differ





          • Debian:



            sudo apt install libsource-highlight-common source-highlight
            dpkg -L libsource-highlight-common | grep lesspipe
            # /usr/share/source-highlight/src-hilite-lesspipe.sh



          • Fedora:



            sudo dnf install source-highlight
            rpm -ql source-highlight | grep lesspipe
            # /usr/bin/source-highlight/src-hilite-lesspipe.sh







          share|improve this answer


























          • I retrieve the following error message when I run less ~/.zshrc. Error: src-hilite-lesspipe.sh: line 9: source-highlight: command not found. I run this on MacOSX.

            – JJD
            Jun 4 '12 at 16:38






          • 2





            @JJD Did you install source-highlight?

            – Max Nanasy
            Aug 31 '12 at 6:00






          • 13





            OSX: brew install source-highlight; export LESSOPEN="| /usr/local/bin/src-hilite-lesspipe.sh %s". Note the path change.

            – Gregg Lind
            Apr 22 '14 at 19:26






          • 22





            On Debian: sudo apt-get install source-highlight, export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s", export LESS=' -R '

            – Morgan Courbet
            Aug 22 '14 at 8:57






          • 3





            small caveat: source-highlight does not currently support markdown.

            – dhulihan
            Jul 7 '16 at 6:10





















          88














          Best of both previous answers: you can invoke system default editor from within less, by pressing v.






          share|improve this answer





















          • 2





            Wow! This is amazingly useful!

            – dancek
            Aug 9 '12 at 5:57






          • 12





            Curses that opened Nano on my Ubuntu box!

            – jamesc
            Jan 18 '13 at 10:12






          • 5





            Then set $EDITOR or $VISUAL to vim (or emacs, or gedit, or joe, or ed, or mined, or…).

            – Daniel H
            Jun 5 '13 at 1:42











          • @jamesc FYI, you can enable syntax highlighting in Nano, here is how.

            – Captain Man
            Apr 14 '16 at 19:00











          • @CaptainMan Nope nope nope! I change the default back to vim like Daniel H said! :D

            – jamesc
            Apr 15 '16 at 15:23



















          32














          pygmentize somefile.ex | less -R


          or



          function cless () {
          pygmentize -f terminal "$1" | less -R
          }


          Pygmentize comes as a part of the Pygments Python syntax highliter.






          share|improve this answer





















          • 3





            pygmentize also works with the LESSOPEN stuff mentioned in other answers here.

            – Nathan
            Aug 5 '14 at 19:01






          • 2





            To get pygmentize, you need Python and then you can install pygmentize with pip install pygments.

            – wkschwartz
            Mar 20 '15 at 1:11






          • 3





            To get less to use pygmentize for syntax highlighting use: which pygmentize 2> /dev/null >&2 && export LESSOPEN="| pygmentize -g -f terminal256 %s". -g to make it work with pipes (less <(diff -u file1 files)). It's available in community/pygmentize package for arch linux, and in python-pygments for debian.

            – x-yuri
            May 16 '15 at 18:38













          • I like the output of pygmentize, but found it to be too slow. I came up with this answer which is faster and still 256-colour pretty.

            – Tom Hale
            Jun 17 '18 at 16:44



















          16














          I think that you should use a text editor. I like vim myself. That will give you LOTS of power when viewing files and then when you want to edit them you will already know the basics.



          Here are some of the advantages of using a text editor (specifically vim):




          • syntax-highlighting

          • powerful movement commands

          • find

          • jump to specific location in a file (called a mark)

          • folding (useful when you just want to see function stubbs)


          To open your file in readonly mode use this:



          vim -R <file name>


          Here is a basic navigation guide:



          j - move down one line
          k - move up one line
          h - left one char
          l -right one char

          ctrl-f - forward one page
          ctrl-b - back one page

          /<something> - search for something
          n - next of whatever you searched for
          N - next (search backwards) of whatever you searched for

          :q - quit
          :q! - quit without saving
          :w - save


          Here is a link for more information:



          http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html



          Just to recap, if you will use unix vim is pretty fundamental. I have heard that learning vim is like learning to type. It is the next most useful tool you can learn for programming.



          (Just to avoid editor wars you could also look into emacs or another editor, however I personally prefer vim)






          share|improve this answer



















          • 1





            I second this. Vim launches as fast as less, and many of the keyboard shortcuts (e.g., search, next page, previous page) are identical.

            – Jeremy W. Sherman
            Feb 10 '11 at 18:20






          • 10





            Just FYI, on a lot of systems, view is an alias for vim -R.

            – Andrew Ferrier
            Sep 18 '12 at 13:12



















          15














          As others have said, you can use the power of vim. But importantly, you can do so without learning how to use vi/vim.



          Vim comes with a less.vim script that works pretty well as a replacement for less, with full color syntax highlighting. It uses less keybindings (just hit 'q' to quit).



          It had a few problems, so I improved it. Here's a screenshot from my blog post on it (archived 2013-04-09; original throws 503):



          screenshot of https://github.com/huyz/less.vim






          share|improve this answer





















          • 2





            Awesome! But as I couldn't find the script right away I'd like to share the command for locating it: find /usr/share/vim -name 'less.sh' which is taken from this gist: gist.github.com/chauncey-garrett/9773770

            – nuala
            Feb 21 '15 at 22:13











          • Adding to @yoshi's comment, to quickly add a vimless command (following the nomenclature of vimdiff), do: ln -s $(find /usr/share/vim -name 'less.sh') /usr/local/bin/vimless

            – waldyrious
            Dec 27 '16 at 12:31











          • The link is 404!

            – acgtyrant
            Jun 22 '18 at 9:24











          • @acgtyrant Should be fixed now; the Internet Archive thankfully has it.

            – bb010g
            11 hours ago



















          10














          I was also searching for this and found another solution using Vim:
          http://ubuntu-tutorials.com/2008/07/14/use-vim-as-a-syntax-highlighting-pager/



          The post is rather old, so now on more recent distros vim 7.2 is shipped and the .bashrc will read:
          alias vless='vim -u /usr/share/vim/vim72/macros/less.vim'






          share|improve this answer





















          • 1





            MacVim comes with a shell script that you can use directly, located in: /Applications/MacVim.app/Contents/Resources/vim/runtime/macros/less.sh

            – Nick
            Jan 14 '12 at 19:23






          • 1





            This feature is documented in Vim itself under :help less

            – joeytwiddle
            Feb 3 '18 at 16:20





















          8














          I'm glad to announce a new package, e2ansi, that provides
          syntax highlighting support for pagers like more and less.



          The package use the mother of all text editors, Emacs, to
          perform the actual syntax highlighting. As an added bonus, all other
          conversions normally performed by Emacs -- like uncompressing files --
          is also performed.



          Example



          The following is the result of viewing a file using less and
          e2ansi:



          Example



          Configuration



          The package provides a command-line tool e2ansi-cat that starts
          Emacs in batch mode, opens files, syntax highlight them, and renders
          the result using ANSI sequences.



          You can integrate this into less by setting the following variables
          to, for example (the location of your init file may vary):



          export "LESSOPEN=||-/usr/local/emacs --batch -Q -l ~/.emacs -l bin/e2ansi-cat %s"
          export "LESS=-r"
          alias "more=less -X -E"


          In the configuration above, less restores the original terminal
          window content whereas more simply output new content after the
          prompt.



          Note: If you use an old version of less, it might not support the
          || or the - syntax, in which case you may need to use simply
          LESSOPEN=|/usr/local/emacs ....



          Using less in pipes



          The "-" character in LESSOPEN indicates that the input filter should
          also be used when piping text into less. In this case, Emacs can
          only rely on text itself (and not a file name). Fortunately, Emacs
          provides a system for this. In addition, the provided file file
          e2ansi-magic.el sets up additional file types. For example:



          Pipe example



          Why use Emacs?




          • Emacs has support for virtually all programming languages and
            structured text formats. In most cases, the syntax highlighting
            support is excellent.

          • You can easily add support for more languages and formats, or modify
            existing packages to suit you needs.

          • Emacs support color themes. When using e2ansi, the colors in the
            theme is preserved when viewing a file in less. You can pick a
            suitable color theme from a number of sources, or design your own.

          • If you use Emacs as your editor of choice, you will get the same
            highlighting in the editor as you get when viewing a file using
            less (minus limitations in ANSI sequence format and the terminal
            window).


          • less will take advantage of Emacs features that perform automatic
            conversion, for example uncompressing files. In fact, you can teach
            Emacs to perform any kind of conversion like automatically convert a
            binary file to human readable form using an external tool.

          • You can view files located on other machines by using Emacs' syntax
            for remote access like /USER@HOST:FILENAME.


          Useful links





          • e2ansi is distributed on Melpa and can be installed using
            the standard Emacs package system


          • e2ansi is hosted on GitHub

          • The e2ansi page on the Emacs Wiki

          • The home of less.


          Operating system notes




          • On MS Windows, the console does not natively support ANSI sequences.
            Fortunately, the less application is capable of rendering them. I
            am not aware of any contemporary binary distribution of less for
            MS Windows and the provided build files is hard to use. Fortunately,
            it's easy to build less using CMake, see this text for
            details.


          • OS X distributes an ancient version of less. Fortunately, it's
            easy to build a modern version directly from the source.







          share|improve this answer
























          • For OS X, I'd recommend using the package manager brew [brew.sh/] with brew dupes [github.com/Homebrew/homebrew-dupes] to install up-to-date versions of things like less.

            – drevicko
            Jan 26 '16 at 10:53













          • "powered by emacs" -- running whole VM just to look at a file? ;-) and +1

            – Alois Mahdal
            Oct 19 '17 at 23:58





















          6














          If you have GNU Source-highlight installed you can use the following command to highlight the syntax of a single file:



          $ src-hilite-lesspipe.sh yourfile.xml | less -R





          share|improve this answer
























          • Can src-hilite-lesspipe.sh receive input via a pipe as well?

            – waldyrious
            Dec 27 '16 at 12:42



















          2














          source-highlight has a .sh script located in /usr/share/source-highlight/*.sh. I've created a symbolic link to it with name hcat in /usr/bin.



          It shows highlighted output in terminal (console) – hcat is highlighted cat.



          How to:



          [me@this]<bash><~> 43 
          21:23 Fri Apr 19 > sudo apt-get install source-highlight

          [me@this]<bash><~> 28
          21:03 Fri Apr 19 > ll /usr/share/source-highlight/*.sh
          -rwxr-xr-x 1 root root 432 May 1 2012 /usr/share/source-highlight/src-hilite-lesspipe.sh*

          [me@this]<bash><~> 29
          21:04 Fri Apr 19 > sudo su
          root@this:/home/me# cd /usr/bin/
          root@this:/usr/bin# ln -s /usr/share/source-highlight/src-hilite-lesspipe.sh hcat

          [me@this]<bash><~> 36
          21:07 Fri Apr 19 > hcat test.xml





          share|improve this answer

































            2














            Using OS X 10.9 (Maverick) this would do the trick:




            • brew install source-highlight (Assuming brew is installed - http://brew.sh)


            • sudo nano /etc/launchd.conf




              setenv LESSOPEN="| /usr/local/bin/src-hilite-lesspipe.sh %s"     
              setenv LESS=' -R '



              (Add to /etc/launchd.conf)



            • reboot







            share|improve this answer































              0














              In mac, you can just type view filename, does similar thing like less.






              share|improve this answer



















              • 1





                With OSX, view filename just launches vim by default - slightly different key bindings to less (see other answers to this question for more details).

                – drevicko
                Jan 26 '16 at 10:56





















              0














              After installing GNU's source-highlight (package dev-util/source-highlight on sabayon/gentoo), I configured those envs in /etc/bash/bashrc.d/my-less-src-highlight:



              #default:    export LESSOPEN="|lesspipe %s"
              #don't like: export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s"
              #default: export LESS=" -R -M --shift 5"
              export LESSCOLOR=always
              export LESSCOLORIZER=/usr/bin/src-hilite-lesspipe.sh


              I did not like to replace lesspipe because that has other features. Concatenation did not work.






              share|improve this answer































                0














                If you want the same syntax highlighting you use in Vim, but for some reason you prefer to use less as your pager, you can use this script: https://github.com/rkitover/vimpager



                The basic usage would be:



                vimpager file.txt


                or



                vimcat file.ext | less -R


                You can use -c to pass extra commands which aren't in your .vimrc (e.g. selecting a different colorscheme). The full command I use is:



                vimcat -c 'set cmdheight=20' -c 'hi! clear Normal' -o - "$FILENAME" | less -REXS


                Beware: If your Vim asks you to press Enter when it starts up, you won't see the prompt, but nothing will happen until you press Enter! The cmdheight trick above can help to mitigate that.






                share|improve this answer































                  0














                  I found highlight which:




                  • Supports multiple colour schemes and 256-colours

                  • Works on STDIN (unlike source-highlight)

                  • Is much faster than pygmentize


                  Screenshot



                  Here is a script I call highlight-less-wrapper which includes .bashrc instructions on how to setup less to use it automatically.



                  #!/bin/bash

                  # Have highlight read from STDIN if '-' is given as filename

                  # Setup - Add to .bashrc:
                  # LESSOPEN='|-highlight-less-wrapper "%s"'
                  # export LESS=-FMRXis

                  # Usage:
                  # $ less file
                  # OR
                  # $ pipeline | less

                  warn () { printf "%s: %sn" "$(basename "$0")" "$*" 1>&2; }
                  die () { warn "$@"; exit 1; }

                  # Argument checking
                  case $# in
                  0)
                  # Allow `exec $0` for less setup
                  echo "LESSOPEN='|-$(readlink -f "$0") "'"%s"''
                  exit 255 ;;
                  1)
                  # Only one argument is expected.
                  # less will invoke multiple times given multiple files.
                  file=$1
                  if [[ $file != - && ! -r $file ]]; then # less passes '-' for STDIN
                  die "Cannot open $file for reading"
                  fi ;;
                  *)
                  die "Expected only one argument" ;;
                  esac

                  # Run highlight
                  # highlight will read from STDIN when given a null filename
                  run_highlight () {
                  highlight --force -O truecolor --style aiseered "$1"
                  }

                  if [[ $file == - ]]; then # Run on stdin
                  run_highlight ""
                  else
                  run_highlight "$file"
                  fi





                  share|improve this answer


























                  • "Since Github is now part of Mordor Corp, the highlight Git repo moved" Was interested, but cmon it's not the 90's anymore devs need to grow up.

                    – Urda
                    Oct 2 '18 at 19:15





















                  0














                  I had the same question and I landed hear, read all answers and the following is what I finally did to have syntax highlighting everytime I use less or most:



                  sudo apt install source-highlight


                  Then I went and created an alias for my less and most (I use ZSH, but you can add aliases for your .bashrc file if you use bash):



                  vim ~/.zshrc


                  (For those who might get stuck in vim: press i to go to edit mode, when you are done press Esc then : then x and finally
                  Enter to save the changes
                  )



                  And paste the following lines for debian-based distros (like Debian, Ubuntu, Mint, etc.):



                  alias most='AliasFuncLess() { unset -f AliasFuncLess; $(dpkg -L libsource-highlight-common | grep lesspipe) "$1" | less -R };AliasFuncLess'
                  alias most='AliasFuncMost() { unset -f AliasFuncMost; $(dpkg -L libsource-highlight-common | grep lesspipe) "$1" | most };AliasFuncMost'


                  or for RPM distros (Redhat, Fedora, Centos):



                  alias most='AliasFuncLess() { unset -f AliasFuncLess; $(rpm -ql source-highlight | grep lesspipe) "$1" | less -R };AliasFuncLess'
                  alias most='AliasFuncMost() { unset -f AliasFuncMost; $(rpm -ql source-highlight | grep lesspipe) "$1" | most };AliasFuncMost'


                  Remember to close the terminal and open it again to make sure alias is created.



                  Now you can enjoy the colors:



                  most yourFile.xml





                  share|improve this answer


























                    Your Answer








                    StackExchange.ready(function() {
                    var channelOptions = {
                    tags: "".split(" "),
                    id: "3"
                    };
                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

                    StackExchange.using("externalEditor", function() {
                    // Have to fire editor after snippets, if snippets enabled
                    if (StackExchange.settings.snippets.snippetsEnabled) {
                    StackExchange.using("snippets", function() {
                    createEditor();
                    });
                    }
                    else {
                    createEditor();
                    }
                    });

                    function createEditor() {
                    StackExchange.prepareEditor({
                    heartbeatType: 'answer',
                    autoActivateHeartbeat: false,
                    convertImagesToLinks: true,
                    noModals: true,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: 10,
                    bindNavPrevention: true,
                    postfix: "",
                    imageUploader: {
                    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                    allowUrls: true
                    },
                    onDemand: true,
                    discardSelector: ".discard-answer"
                    ,immediatelyShowMarkdownHelp:true
                    });


                    }
                    });














                    draft saved

                    draft discarded


















                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f71588%2fhow-to-syntax-highlight-via-less%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown

























                    15 Answers
                    15






                    active

                    oldest

                    votes








                    15 Answers
                    15






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes









                    120














                    You can use GNU's source-highlight, as shown here (path may differ, see below):



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


                    As of Debian Stretch and Fedora 25, package names and script paths differ





                    • Debian:



                      sudo apt install libsource-highlight-common source-highlight
                      dpkg -L libsource-highlight-common | grep lesspipe
                      # /usr/share/source-highlight/src-hilite-lesspipe.sh



                    • Fedora:



                      sudo dnf install source-highlight
                      rpm -ql source-highlight | grep lesspipe
                      # /usr/bin/source-highlight/src-hilite-lesspipe.sh







                    share|improve this answer


























                    • I retrieve the following error message when I run less ~/.zshrc. Error: src-hilite-lesspipe.sh: line 9: source-highlight: command not found. I run this on MacOSX.

                      – JJD
                      Jun 4 '12 at 16:38






                    • 2





                      @JJD Did you install source-highlight?

                      – Max Nanasy
                      Aug 31 '12 at 6:00






                    • 13





                      OSX: brew install source-highlight; export LESSOPEN="| /usr/local/bin/src-hilite-lesspipe.sh %s". Note the path change.

                      – Gregg Lind
                      Apr 22 '14 at 19:26






                    • 22





                      On Debian: sudo apt-get install source-highlight, export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s", export LESS=' -R '

                      – Morgan Courbet
                      Aug 22 '14 at 8:57






                    • 3





                      small caveat: source-highlight does not currently support markdown.

                      – dhulihan
                      Jul 7 '16 at 6:10


















                    120














                    You can use GNU's source-highlight, as shown here (path may differ, see below):



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


                    As of Debian Stretch and Fedora 25, package names and script paths differ





                    • Debian:



                      sudo apt install libsource-highlight-common source-highlight
                      dpkg -L libsource-highlight-common | grep lesspipe
                      # /usr/share/source-highlight/src-hilite-lesspipe.sh



                    • Fedora:



                      sudo dnf install source-highlight
                      rpm -ql source-highlight | grep lesspipe
                      # /usr/bin/source-highlight/src-hilite-lesspipe.sh







                    share|improve this answer


























                    • I retrieve the following error message when I run less ~/.zshrc. Error: src-hilite-lesspipe.sh: line 9: source-highlight: command not found. I run this on MacOSX.

                      – JJD
                      Jun 4 '12 at 16:38






                    • 2





                      @JJD Did you install source-highlight?

                      – Max Nanasy
                      Aug 31 '12 at 6:00






                    • 13





                      OSX: brew install source-highlight; export LESSOPEN="| /usr/local/bin/src-hilite-lesspipe.sh %s". Note the path change.

                      – Gregg Lind
                      Apr 22 '14 at 19:26






                    • 22





                      On Debian: sudo apt-get install source-highlight, export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s", export LESS=' -R '

                      – Morgan Courbet
                      Aug 22 '14 at 8:57






                    • 3





                      small caveat: source-highlight does not currently support markdown.

                      – dhulihan
                      Jul 7 '16 at 6:10
















                    120












                    120








                    120







                    You can use GNU's source-highlight, as shown here (path may differ, see below):



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


                    As of Debian Stretch and Fedora 25, package names and script paths differ





                    • Debian:



                      sudo apt install libsource-highlight-common source-highlight
                      dpkg -L libsource-highlight-common | grep lesspipe
                      # /usr/share/source-highlight/src-hilite-lesspipe.sh



                    • Fedora:



                      sudo dnf install source-highlight
                      rpm -ql source-highlight | grep lesspipe
                      # /usr/bin/source-highlight/src-hilite-lesspipe.sh







                    share|improve this answer















                    You can use GNU's source-highlight, as shown here (path may differ, see below):



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


                    As of Debian Stretch and Fedora 25, package names and script paths differ





                    • Debian:



                      sudo apt install libsource-highlight-common source-highlight
                      dpkg -L libsource-highlight-common | grep lesspipe
                      # /usr/share/source-highlight/src-hilite-lesspipe.sh



                    • Fedora:



                      sudo dnf install source-highlight
                      rpm -ql source-highlight | grep lesspipe
                      # /usr/bin/source-highlight/src-hilite-lesspipe.sh








                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Feb 1 at 17:29









                    Pablo Bianchi

                    273111




                    273111










                    answered Nov 17 '09 at 10:35









                    brandstaetterbrandstaetter

                    3,99421820




                    3,99421820













                    • I retrieve the following error message when I run less ~/.zshrc. Error: src-hilite-lesspipe.sh: line 9: source-highlight: command not found. I run this on MacOSX.

                      – JJD
                      Jun 4 '12 at 16:38






                    • 2





                      @JJD Did you install source-highlight?

                      – Max Nanasy
                      Aug 31 '12 at 6:00






                    • 13





                      OSX: brew install source-highlight; export LESSOPEN="| /usr/local/bin/src-hilite-lesspipe.sh %s". Note the path change.

                      – Gregg Lind
                      Apr 22 '14 at 19:26






                    • 22





                      On Debian: sudo apt-get install source-highlight, export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s", export LESS=' -R '

                      – Morgan Courbet
                      Aug 22 '14 at 8:57






                    • 3





                      small caveat: source-highlight does not currently support markdown.

                      – dhulihan
                      Jul 7 '16 at 6:10





















                    • I retrieve the following error message when I run less ~/.zshrc. Error: src-hilite-lesspipe.sh: line 9: source-highlight: command not found. I run this on MacOSX.

                      – JJD
                      Jun 4 '12 at 16:38






                    • 2





                      @JJD Did you install source-highlight?

                      – Max Nanasy
                      Aug 31 '12 at 6:00






                    • 13





                      OSX: brew install source-highlight; export LESSOPEN="| /usr/local/bin/src-hilite-lesspipe.sh %s". Note the path change.

                      – Gregg Lind
                      Apr 22 '14 at 19:26






                    • 22





                      On Debian: sudo apt-get install source-highlight, export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s", export LESS=' -R '

                      – Morgan Courbet
                      Aug 22 '14 at 8:57






                    • 3





                      small caveat: source-highlight does not currently support markdown.

                      – dhulihan
                      Jul 7 '16 at 6:10



















                    I retrieve the following error message when I run less ~/.zshrc. Error: src-hilite-lesspipe.sh: line 9: source-highlight: command not found. I run this on MacOSX.

                    – JJD
                    Jun 4 '12 at 16:38





                    I retrieve the following error message when I run less ~/.zshrc. Error: src-hilite-lesspipe.sh: line 9: source-highlight: command not found. I run this on MacOSX.

                    – JJD
                    Jun 4 '12 at 16:38




                    2




                    2





                    @JJD Did you install source-highlight?

                    – Max Nanasy
                    Aug 31 '12 at 6:00





                    @JJD Did you install source-highlight?

                    – Max Nanasy
                    Aug 31 '12 at 6:00




                    13




                    13





                    OSX: brew install source-highlight; export LESSOPEN="| /usr/local/bin/src-hilite-lesspipe.sh %s". Note the path change.

                    – Gregg Lind
                    Apr 22 '14 at 19:26





                    OSX: brew install source-highlight; export LESSOPEN="| /usr/local/bin/src-hilite-lesspipe.sh %s". Note the path change.

                    – Gregg Lind
                    Apr 22 '14 at 19:26




                    22




                    22





                    On Debian: sudo apt-get install source-highlight, export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s", export LESS=' -R '

                    – Morgan Courbet
                    Aug 22 '14 at 8:57





                    On Debian: sudo apt-get install source-highlight, export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s", export LESS=' -R '

                    – Morgan Courbet
                    Aug 22 '14 at 8:57




                    3




                    3





                    small caveat: source-highlight does not currently support markdown.

                    – dhulihan
                    Jul 7 '16 at 6:10







                    small caveat: source-highlight does not currently support markdown.

                    – dhulihan
                    Jul 7 '16 at 6:10















                    88














                    Best of both previous answers: you can invoke system default editor from within less, by pressing v.






                    share|improve this answer





















                    • 2





                      Wow! This is amazingly useful!

                      – dancek
                      Aug 9 '12 at 5:57






                    • 12





                      Curses that opened Nano on my Ubuntu box!

                      – jamesc
                      Jan 18 '13 at 10:12






                    • 5





                      Then set $EDITOR or $VISUAL to vim (or emacs, or gedit, or joe, or ed, or mined, or…).

                      – Daniel H
                      Jun 5 '13 at 1:42











                    • @jamesc FYI, you can enable syntax highlighting in Nano, here is how.

                      – Captain Man
                      Apr 14 '16 at 19:00











                    • @CaptainMan Nope nope nope! I change the default back to vim like Daniel H said! :D

                      – jamesc
                      Apr 15 '16 at 15:23
















                    88














                    Best of both previous answers: you can invoke system default editor from within less, by pressing v.






                    share|improve this answer





















                    • 2





                      Wow! This is amazingly useful!

                      – dancek
                      Aug 9 '12 at 5:57






                    • 12





                      Curses that opened Nano on my Ubuntu box!

                      – jamesc
                      Jan 18 '13 at 10:12






                    • 5





                      Then set $EDITOR or $VISUAL to vim (or emacs, or gedit, or joe, or ed, or mined, or…).

                      – Daniel H
                      Jun 5 '13 at 1:42











                    • @jamesc FYI, you can enable syntax highlighting in Nano, here is how.

                      – Captain Man
                      Apr 14 '16 at 19:00











                    • @CaptainMan Nope nope nope! I change the default back to vim like Daniel H said! :D

                      – jamesc
                      Apr 15 '16 at 15:23














                    88












                    88








                    88







                    Best of both previous answers: you can invoke system default editor from within less, by pressing v.






                    share|improve this answer















                    Best of both previous answers: you can invoke system default editor from within less, by pressing v.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Feb 5 '14 at 21:36









                    Mxx

                    2,53821534




                    2,53821534










                    answered Aug 24 '10 at 17:14







                    JiM















                    • 2





                      Wow! This is amazingly useful!

                      – dancek
                      Aug 9 '12 at 5:57






                    • 12





                      Curses that opened Nano on my Ubuntu box!

                      – jamesc
                      Jan 18 '13 at 10:12






                    • 5





                      Then set $EDITOR or $VISUAL to vim (or emacs, or gedit, or joe, or ed, or mined, or…).

                      – Daniel H
                      Jun 5 '13 at 1:42











                    • @jamesc FYI, you can enable syntax highlighting in Nano, here is how.

                      – Captain Man
                      Apr 14 '16 at 19:00











                    • @CaptainMan Nope nope nope! I change the default back to vim like Daniel H said! :D

                      – jamesc
                      Apr 15 '16 at 15:23














                    • 2





                      Wow! This is amazingly useful!

                      – dancek
                      Aug 9 '12 at 5:57






                    • 12





                      Curses that opened Nano on my Ubuntu box!

                      – jamesc
                      Jan 18 '13 at 10:12






                    • 5





                      Then set $EDITOR or $VISUAL to vim (or emacs, or gedit, or joe, or ed, or mined, or…).

                      – Daniel H
                      Jun 5 '13 at 1:42











                    • @jamesc FYI, you can enable syntax highlighting in Nano, here is how.

                      – Captain Man
                      Apr 14 '16 at 19:00











                    • @CaptainMan Nope nope nope! I change the default back to vim like Daniel H said! :D

                      – jamesc
                      Apr 15 '16 at 15:23








                    2




                    2





                    Wow! This is amazingly useful!

                    – dancek
                    Aug 9 '12 at 5:57





                    Wow! This is amazingly useful!

                    – dancek
                    Aug 9 '12 at 5:57




                    12




                    12





                    Curses that opened Nano on my Ubuntu box!

                    – jamesc
                    Jan 18 '13 at 10:12





                    Curses that opened Nano on my Ubuntu box!

                    – jamesc
                    Jan 18 '13 at 10:12




                    5




                    5





                    Then set $EDITOR or $VISUAL to vim (or emacs, or gedit, or joe, or ed, or mined, or…).

                    – Daniel H
                    Jun 5 '13 at 1:42





                    Then set $EDITOR or $VISUAL to vim (or emacs, or gedit, or joe, or ed, or mined, or…).

                    – Daniel H
                    Jun 5 '13 at 1:42













                    @jamesc FYI, you can enable syntax highlighting in Nano, here is how.

                    – Captain Man
                    Apr 14 '16 at 19:00





                    @jamesc FYI, you can enable syntax highlighting in Nano, here is how.

                    – Captain Man
                    Apr 14 '16 at 19:00













                    @CaptainMan Nope nope nope! I change the default back to vim like Daniel H said! :D

                    – jamesc
                    Apr 15 '16 at 15:23





                    @CaptainMan Nope nope nope! I change the default back to vim like Daniel H said! :D

                    – jamesc
                    Apr 15 '16 at 15:23











                    32














                    pygmentize somefile.ex | less -R


                    or



                    function cless () {
                    pygmentize -f terminal "$1" | less -R
                    }


                    Pygmentize comes as a part of the Pygments Python syntax highliter.






                    share|improve this answer





















                    • 3





                      pygmentize also works with the LESSOPEN stuff mentioned in other answers here.

                      – Nathan
                      Aug 5 '14 at 19:01






                    • 2





                      To get pygmentize, you need Python and then you can install pygmentize with pip install pygments.

                      – wkschwartz
                      Mar 20 '15 at 1:11






                    • 3





                      To get less to use pygmentize for syntax highlighting use: which pygmentize 2> /dev/null >&2 && export LESSOPEN="| pygmentize -g -f terminal256 %s". -g to make it work with pipes (less <(diff -u file1 files)). It's available in community/pygmentize package for arch linux, and in python-pygments for debian.

                      – x-yuri
                      May 16 '15 at 18:38













                    • I like the output of pygmentize, but found it to be too slow. I came up with this answer which is faster and still 256-colour pretty.

                      – Tom Hale
                      Jun 17 '18 at 16:44
















                    32














                    pygmentize somefile.ex | less -R


                    or



                    function cless () {
                    pygmentize -f terminal "$1" | less -R
                    }


                    Pygmentize comes as a part of the Pygments Python syntax highliter.






                    share|improve this answer





















                    • 3





                      pygmentize also works with the LESSOPEN stuff mentioned in other answers here.

                      – Nathan
                      Aug 5 '14 at 19:01






                    • 2





                      To get pygmentize, you need Python and then you can install pygmentize with pip install pygments.

                      – wkschwartz
                      Mar 20 '15 at 1:11






                    • 3





                      To get less to use pygmentize for syntax highlighting use: which pygmentize 2> /dev/null >&2 && export LESSOPEN="| pygmentize -g -f terminal256 %s". -g to make it work with pipes (less <(diff -u file1 files)). It's available in community/pygmentize package for arch linux, and in python-pygments for debian.

                      – x-yuri
                      May 16 '15 at 18:38













                    • I like the output of pygmentize, but found it to be too slow. I came up with this answer which is faster and still 256-colour pretty.

                      – Tom Hale
                      Jun 17 '18 at 16:44














                    32












                    32








                    32







                    pygmentize somefile.ex | less -R


                    or



                    function cless () {
                    pygmentize -f terminal "$1" | less -R
                    }


                    Pygmentize comes as a part of the Pygments Python syntax highliter.






                    share|improve this answer















                    pygmentize somefile.ex | less -R


                    or



                    function cless () {
                    pygmentize -f terminal "$1" | less -R
                    }


                    Pygmentize comes as a part of the Pygments Python syntax highliter.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Apr 16 '15 at 9:22









                    Razvan Stefanescu

                    1034




                    1034










                    answered Aug 24 '10 at 18:25







                    user31752















                    • 3





                      pygmentize also works with the LESSOPEN stuff mentioned in other answers here.

                      – Nathan
                      Aug 5 '14 at 19:01






                    • 2





                      To get pygmentize, you need Python and then you can install pygmentize with pip install pygments.

                      – wkschwartz
                      Mar 20 '15 at 1:11






                    • 3





                      To get less to use pygmentize for syntax highlighting use: which pygmentize 2> /dev/null >&2 && export LESSOPEN="| pygmentize -g -f terminal256 %s". -g to make it work with pipes (less <(diff -u file1 files)). It's available in community/pygmentize package for arch linux, and in python-pygments for debian.

                      – x-yuri
                      May 16 '15 at 18:38













                    • I like the output of pygmentize, but found it to be too slow. I came up with this answer which is faster and still 256-colour pretty.

                      – Tom Hale
                      Jun 17 '18 at 16:44














                    • 3





                      pygmentize also works with the LESSOPEN stuff mentioned in other answers here.

                      – Nathan
                      Aug 5 '14 at 19:01






                    • 2





                      To get pygmentize, you need Python and then you can install pygmentize with pip install pygments.

                      – wkschwartz
                      Mar 20 '15 at 1:11






                    • 3





                      To get less to use pygmentize for syntax highlighting use: which pygmentize 2> /dev/null >&2 && export LESSOPEN="| pygmentize -g -f terminal256 %s". -g to make it work with pipes (less <(diff -u file1 files)). It's available in community/pygmentize package for arch linux, and in python-pygments for debian.

                      – x-yuri
                      May 16 '15 at 18:38













                    • I like the output of pygmentize, but found it to be too slow. I came up with this answer which is faster and still 256-colour pretty.

                      – Tom Hale
                      Jun 17 '18 at 16:44








                    3




                    3





                    pygmentize also works with the LESSOPEN stuff mentioned in other answers here.

                    – Nathan
                    Aug 5 '14 at 19:01





                    pygmentize also works with the LESSOPEN stuff mentioned in other answers here.

                    – Nathan
                    Aug 5 '14 at 19:01




                    2




                    2





                    To get pygmentize, you need Python and then you can install pygmentize with pip install pygments.

                    – wkschwartz
                    Mar 20 '15 at 1:11





                    To get pygmentize, you need Python and then you can install pygmentize with pip install pygments.

                    – wkschwartz
                    Mar 20 '15 at 1:11




                    3




                    3





                    To get less to use pygmentize for syntax highlighting use: which pygmentize 2> /dev/null >&2 && export LESSOPEN="| pygmentize -g -f terminal256 %s". -g to make it work with pipes (less <(diff -u file1 files)). It's available in community/pygmentize package for arch linux, and in python-pygments for debian.

                    – x-yuri
                    May 16 '15 at 18:38







                    To get less to use pygmentize for syntax highlighting use: which pygmentize 2> /dev/null >&2 && export LESSOPEN="| pygmentize -g -f terminal256 %s". -g to make it work with pipes (less <(diff -u file1 files)). It's available in community/pygmentize package for arch linux, and in python-pygments for debian.

                    – x-yuri
                    May 16 '15 at 18:38















                    I like the output of pygmentize, but found it to be too slow. I came up with this answer which is faster and still 256-colour pretty.

                    – Tom Hale
                    Jun 17 '18 at 16:44





                    I like the output of pygmentize, but found it to be too slow. I came up with this answer which is faster and still 256-colour pretty.

                    – Tom Hale
                    Jun 17 '18 at 16:44











                    16














                    I think that you should use a text editor. I like vim myself. That will give you LOTS of power when viewing files and then when you want to edit them you will already know the basics.



                    Here are some of the advantages of using a text editor (specifically vim):




                    • syntax-highlighting

                    • powerful movement commands

                    • find

                    • jump to specific location in a file (called a mark)

                    • folding (useful when you just want to see function stubbs)


                    To open your file in readonly mode use this:



                    vim -R <file name>


                    Here is a basic navigation guide:



                    j - move down one line
                    k - move up one line
                    h - left one char
                    l -right one char

                    ctrl-f - forward one page
                    ctrl-b - back one page

                    /<something> - search for something
                    n - next of whatever you searched for
                    N - next (search backwards) of whatever you searched for

                    :q - quit
                    :q! - quit without saving
                    :w - save


                    Here is a link for more information:



                    http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html



                    Just to recap, if you will use unix vim is pretty fundamental. I have heard that learning vim is like learning to type. It is the next most useful tool you can learn for programming.



                    (Just to avoid editor wars you could also look into emacs or another editor, however I personally prefer vim)






                    share|improve this answer



















                    • 1





                      I second this. Vim launches as fast as less, and many of the keyboard shortcuts (e.g., search, next page, previous page) are identical.

                      – Jeremy W. Sherman
                      Feb 10 '11 at 18:20






                    • 10





                      Just FYI, on a lot of systems, view is an alias for vim -R.

                      – Andrew Ferrier
                      Sep 18 '12 at 13:12
















                    16














                    I think that you should use a text editor. I like vim myself. That will give you LOTS of power when viewing files and then when you want to edit them you will already know the basics.



                    Here are some of the advantages of using a text editor (specifically vim):




                    • syntax-highlighting

                    • powerful movement commands

                    • find

                    • jump to specific location in a file (called a mark)

                    • folding (useful when you just want to see function stubbs)


                    To open your file in readonly mode use this:



                    vim -R <file name>


                    Here is a basic navigation guide:



                    j - move down one line
                    k - move up one line
                    h - left one char
                    l -right one char

                    ctrl-f - forward one page
                    ctrl-b - back one page

                    /<something> - search for something
                    n - next of whatever you searched for
                    N - next (search backwards) of whatever you searched for

                    :q - quit
                    :q! - quit without saving
                    :w - save


                    Here is a link for more information:



                    http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html



                    Just to recap, if you will use unix vim is pretty fundamental. I have heard that learning vim is like learning to type. It is the next most useful tool you can learn for programming.



                    (Just to avoid editor wars you could also look into emacs or another editor, however I personally prefer vim)






                    share|improve this answer



















                    • 1





                      I second this. Vim launches as fast as less, and many of the keyboard shortcuts (e.g., search, next page, previous page) are identical.

                      – Jeremy W. Sherman
                      Feb 10 '11 at 18:20






                    • 10





                      Just FYI, on a lot of systems, view is an alias for vim -R.

                      – Andrew Ferrier
                      Sep 18 '12 at 13:12














                    16












                    16








                    16







                    I think that you should use a text editor. I like vim myself. That will give you LOTS of power when viewing files and then when you want to edit them you will already know the basics.



                    Here are some of the advantages of using a text editor (specifically vim):




                    • syntax-highlighting

                    • powerful movement commands

                    • find

                    • jump to specific location in a file (called a mark)

                    • folding (useful when you just want to see function stubbs)


                    To open your file in readonly mode use this:



                    vim -R <file name>


                    Here is a basic navigation guide:



                    j - move down one line
                    k - move up one line
                    h - left one char
                    l -right one char

                    ctrl-f - forward one page
                    ctrl-b - back one page

                    /<something> - search for something
                    n - next of whatever you searched for
                    N - next (search backwards) of whatever you searched for

                    :q - quit
                    :q! - quit without saving
                    :w - save


                    Here is a link for more information:



                    http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html



                    Just to recap, if you will use unix vim is pretty fundamental. I have heard that learning vim is like learning to type. It is the next most useful tool you can learn for programming.



                    (Just to avoid editor wars you could also look into emacs or another editor, however I personally prefer vim)






                    share|improve this answer













                    I think that you should use a text editor. I like vim myself. That will give you LOTS of power when viewing files and then when you want to edit them you will already know the basics.



                    Here are some of the advantages of using a text editor (specifically vim):




                    • syntax-highlighting

                    • powerful movement commands

                    • find

                    • jump to specific location in a file (called a mark)

                    • folding (useful when you just want to see function stubbs)


                    To open your file in readonly mode use this:



                    vim -R <file name>


                    Here is a basic navigation guide:



                    j - move down one line
                    k - move up one line
                    h - left one char
                    l -right one char

                    ctrl-f - forward one page
                    ctrl-b - back one page

                    /<something> - search for something
                    n - next of whatever you searched for
                    N - next (search backwards) of whatever you searched for

                    :q - quit
                    :q! - quit without saving
                    :w - save


                    Here is a link for more information:



                    http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html



                    Just to recap, if you will use unix vim is pretty fundamental. I have heard that learning vim is like learning to type. It is the next most useful tool you can learn for programming.



                    (Just to avoid editor wars you could also look into emacs or another editor, however I personally prefer vim)







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 1 '10 at 22:18









                    sixtyfootersdudesixtyfootersdude

                    3,240134267




                    3,240134267








                    • 1





                      I second this. Vim launches as fast as less, and many of the keyboard shortcuts (e.g., search, next page, previous page) are identical.

                      – Jeremy W. Sherman
                      Feb 10 '11 at 18:20






                    • 10





                      Just FYI, on a lot of systems, view is an alias for vim -R.

                      – Andrew Ferrier
                      Sep 18 '12 at 13:12














                    • 1





                      I second this. Vim launches as fast as less, and many of the keyboard shortcuts (e.g., search, next page, previous page) are identical.

                      – Jeremy W. Sherman
                      Feb 10 '11 at 18:20






                    • 10





                      Just FYI, on a lot of systems, view is an alias for vim -R.

                      – Andrew Ferrier
                      Sep 18 '12 at 13:12








                    1




                    1





                    I second this. Vim launches as fast as less, and many of the keyboard shortcuts (e.g., search, next page, previous page) are identical.

                    – Jeremy W. Sherman
                    Feb 10 '11 at 18:20





                    I second this. Vim launches as fast as less, and many of the keyboard shortcuts (e.g., search, next page, previous page) are identical.

                    – Jeremy W. Sherman
                    Feb 10 '11 at 18:20




                    10




                    10





                    Just FYI, on a lot of systems, view is an alias for vim -R.

                    – Andrew Ferrier
                    Sep 18 '12 at 13:12





                    Just FYI, on a lot of systems, view is an alias for vim -R.

                    – Andrew Ferrier
                    Sep 18 '12 at 13:12











                    15














                    As others have said, you can use the power of vim. But importantly, you can do so without learning how to use vi/vim.



                    Vim comes with a less.vim script that works pretty well as a replacement for less, with full color syntax highlighting. It uses less keybindings (just hit 'q' to quit).



                    It had a few problems, so I improved it. Here's a screenshot from my blog post on it (archived 2013-04-09; original throws 503):



                    screenshot of https://github.com/huyz/less.vim






                    share|improve this answer





















                    • 2





                      Awesome! But as I couldn't find the script right away I'd like to share the command for locating it: find /usr/share/vim -name 'less.sh' which is taken from this gist: gist.github.com/chauncey-garrett/9773770

                      – nuala
                      Feb 21 '15 at 22:13











                    • Adding to @yoshi's comment, to quickly add a vimless command (following the nomenclature of vimdiff), do: ln -s $(find /usr/share/vim -name 'less.sh') /usr/local/bin/vimless

                      – waldyrious
                      Dec 27 '16 at 12:31











                    • The link is 404!

                      – acgtyrant
                      Jun 22 '18 at 9:24











                    • @acgtyrant Should be fixed now; the Internet Archive thankfully has it.

                      – bb010g
                      11 hours ago
















                    15














                    As others have said, you can use the power of vim. But importantly, you can do so without learning how to use vi/vim.



                    Vim comes with a less.vim script that works pretty well as a replacement for less, with full color syntax highlighting. It uses less keybindings (just hit 'q' to quit).



                    It had a few problems, so I improved it. Here's a screenshot from my blog post on it (archived 2013-04-09; original throws 503):



                    screenshot of https://github.com/huyz/less.vim






                    share|improve this answer





















                    • 2





                      Awesome! But as I couldn't find the script right away I'd like to share the command for locating it: find /usr/share/vim -name 'less.sh' which is taken from this gist: gist.github.com/chauncey-garrett/9773770

                      – nuala
                      Feb 21 '15 at 22:13











                    • Adding to @yoshi's comment, to quickly add a vimless command (following the nomenclature of vimdiff), do: ln -s $(find /usr/share/vim -name 'less.sh') /usr/local/bin/vimless

                      – waldyrious
                      Dec 27 '16 at 12:31











                    • The link is 404!

                      – acgtyrant
                      Jun 22 '18 at 9:24











                    • @acgtyrant Should be fixed now; the Internet Archive thankfully has it.

                      – bb010g
                      11 hours ago














                    15












                    15








                    15







                    As others have said, you can use the power of vim. But importantly, you can do so without learning how to use vi/vim.



                    Vim comes with a less.vim script that works pretty well as a replacement for less, with full color syntax highlighting. It uses less keybindings (just hit 'q' to quit).



                    It had a few problems, so I improved it. Here's a screenshot from my blog post on it (archived 2013-04-09; original throws 503):



                    screenshot of https://github.com/huyz/less.vim






                    share|improve this answer















                    As others have said, you can use the power of vim. But importantly, you can do so without learning how to use vi/vim.



                    Vim comes with a less.vim script that works pretty well as a replacement for less, with full color syntax highlighting. It uses less keybindings (just hit 'q' to quit).



                    It had a few problems, so I improved it. Here's a screenshot from my blog post on it (archived 2013-04-09; original throws 503):



                    screenshot of https://github.com/huyz/less.vim







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 7 hours ago









                    bb010g

                    458317




                    458317










                    answered Jul 4 '11 at 5:35









                    huyzhuyz

                    28738




                    28738








                    • 2





                      Awesome! But as I couldn't find the script right away I'd like to share the command for locating it: find /usr/share/vim -name 'less.sh' which is taken from this gist: gist.github.com/chauncey-garrett/9773770

                      – nuala
                      Feb 21 '15 at 22:13











                    • Adding to @yoshi's comment, to quickly add a vimless command (following the nomenclature of vimdiff), do: ln -s $(find /usr/share/vim -name 'less.sh') /usr/local/bin/vimless

                      – waldyrious
                      Dec 27 '16 at 12:31











                    • The link is 404!

                      – acgtyrant
                      Jun 22 '18 at 9:24











                    • @acgtyrant Should be fixed now; the Internet Archive thankfully has it.

                      – bb010g
                      11 hours ago














                    • 2





                      Awesome! But as I couldn't find the script right away I'd like to share the command for locating it: find /usr/share/vim -name 'less.sh' which is taken from this gist: gist.github.com/chauncey-garrett/9773770

                      – nuala
                      Feb 21 '15 at 22:13











                    • Adding to @yoshi's comment, to quickly add a vimless command (following the nomenclature of vimdiff), do: ln -s $(find /usr/share/vim -name 'less.sh') /usr/local/bin/vimless

                      – waldyrious
                      Dec 27 '16 at 12:31











                    • The link is 404!

                      – acgtyrant
                      Jun 22 '18 at 9:24











                    • @acgtyrant Should be fixed now; the Internet Archive thankfully has it.

                      – bb010g
                      11 hours ago








                    2




                    2





                    Awesome! But as I couldn't find the script right away I'd like to share the command for locating it: find /usr/share/vim -name 'less.sh' which is taken from this gist: gist.github.com/chauncey-garrett/9773770

                    – nuala
                    Feb 21 '15 at 22:13





                    Awesome! But as I couldn't find the script right away I'd like to share the command for locating it: find /usr/share/vim -name 'less.sh' which is taken from this gist: gist.github.com/chauncey-garrett/9773770

                    – nuala
                    Feb 21 '15 at 22:13













                    Adding to @yoshi's comment, to quickly add a vimless command (following the nomenclature of vimdiff), do: ln -s $(find /usr/share/vim -name 'less.sh') /usr/local/bin/vimless

                    – waldyrious
                    Dec 27 '16 at 12:31





                    Adding to @yoshi's comment, to quickly add a vimless command (following the nomenclature of vimdiff), do: ln -s $(find /usr/share/vim -name 'less.sh') /usr/local/bin/vimless

                    – waldyrious
                    Dec 27 '16 at 12:31













                    The link is 404!

                    – acgtyrant
                    Jun 22 '18 at 9:24





                    The link is 404!

                    – acgtyrant
                    Jun 22 '18 at 9:24













                    @acgtyrant Should be fixed now; the Internet Archive thankfully has it.

                    – bb010g
                    11 hours ago





                    @acgtyrant Should be fixed now; the Internet Archive thankfully has it.

                    – bb010g
                    11 hours ago











                    10














                    I was also searching for this and found another solution using Vim:
                    http://ubuntu-tutorials.com/2008/07/14/use-vim-as-a-syntax-highlighting-pager/



                    The post is rather old, so now on more recent distros vim 7.2 is shipped and the .bashrc will read:
                    alias vless='vim -u /usr/share/vim/vim72/macros/less.vim'






                    share|improve this answer





















                    • 1





                      MacVim comes with a shell script that you can use directly, located in: /Applications/MacVim.app/Contents/Resources/vim/runtime/macros/less.sh

                      – Nick
                      Jan 14 '12 at 19:23






                    • 1





                      This feature is documented in Vim itself under :help less

                      – joeytwiddle
                      Feb 3 '18 at 16:20


















                    10














                    I was also searching for this and found another solution using Vim:
                    http://ubuntu-tutorials.com/2008/07/14/use-vim-as-a-syntax-highlighting-pager/



                    The post is rather old, so now on more recent distros vim 7.2 is shipped and the .bashrc will read:
                    alias vless='vim -u /usr/share/vim/vim72/macros/less.vim'






                    share|improve this answer





















                    • 1





                      MacVim comes with a shell script that you can use directly, located in: /Applications/MacVim.app/Contents/Resources/vim/runtime/macros/less.sh

                      – Nick
                      Jan 14 '12 at 19:23






                    • 1





                      This feature is documented in Vim itself under :help less

                      – joeytwiddle
                      Feb 3 '18 at 16:20
















                    10












                    10








                    10







                    I was also searching for this and found another solution using Vim:
                    http://ubuntu-tutorials.com/2008/07/14/use-vim-as-a-syntax-highlighting-pager/



                    The post is rather old, so now on more recent distros vim 7.2 is shipped and the .bashrc will read:
                    alias vless='vim -u /usr/share/vim/vim72/macros/less.vim'






                    share|improve this answer















                    I was also searching for this and found another solution using Vim:
                    http://ubuntu-tutorials.com/2008/07/14/use-vim-as-a-syntax-highlighting-pager/



                    The post is rather old, so now on more recent distros vim 7.2 is shipped and the .bashrc will read:
                    alias vless='vim -u /usr/share/vim/vim72/macros/less.vim'







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Feb 10 '11 at 13:48

























                    answered Feb 10 '11 at 13:43









                    LorenzoLorenzo

                    10113




                    10113








                    • 1





                      MacVim comes with a shell script that you can use directly, located in: /Applications/MacVim.app/Contents/Resources/vim/runtime/macros/less.sh

                      – Nick
                      Jan 14 '12 at 19:23






                    • 1





                      This feature is documented in Vim itself under :help less

                      – joeytwiddle
                      Feb 3 '18 at 16:20
















                    • 1





                      MacVim comes with a shell script that you can use directly, located in: /Applications/MacVim.app/Contents/Resources/vim/runtime/macros/less.sh

                      – Nick
                      Jan 14 '12 at 19:23






                    • 1





                      This feature is documented in Vim itself under :help less

                      – joeytwiddle
                      Feb 3 '18 at 16:20










                    1




                    1





                    MacVim comes with a shell script that you can use directly, located in: /Applications/MacVim.app/Contents/Resources/vim/runtime/macros/less.sh

                    – Nick
                    Jan 14 '12 at 19:23





                    MacVim comes with a shell script that you can use directly, located in: /Applications/MacVim.app/Contents/Resources/vim/runtime/macros/less.sh

                    – Nick
                    Jan 14 '12 at 19:23




                    1




                    1





                    This feature is documented in Vim itself under :help less

                    – joeytwiddle
                    Feb 3 '18 at 16:20







                    This feature is documented in Vim itself under :help less

                    – joeytwiddle
                    Feb 3 '18 at 16:20













                    8














                    I'm glad to announce a new package, e2ansi, that provides
                    syntax highlighting support for pagers like more and less.



                    The package use the mother of all text editors, Emacs, to
                    perform the actual syntax highlighting. As an added bonus, all other
                    conversions normally performed by Emacs -- like uncompressing files --
                    is also performed.



                    Example



                    The following is the result of viewing a file using less and
                    e2ansi:



                    Example



                    Configuration



                    The package provides a command-line tool e2ansi-cat that starts
                    Emacs in batch mode, opens files, syntax highlight them, and renders
                    the result using ANSI sequences.



                    You can integrate this into less by setting the following variables
                    to, for example (the location of your init file may vary):



                    export "LESSOPEN=||-/usr/local/emacs --batch -Q -l ~/.emacs -l bin/e2ansi-cat %s"
                    export "LESS=-r"
                    alias "more=less -X -E"


                    In the configuration above, less restores the original terminal
                    window content whereas more simply output new content after the
                    prompt.



                    Note: If you use an old version of less, it might not support the
                    || or the - syntax, in which case you may need to use simply
                    LESSOPEN=|/usr/local/emacs ....



                    Using less in pipes



                    The "-" character in LESSOPEN indicates that the input filter should
                    also be used when piping text into less. In this case, Emacs can
                    only rely on text itself (and not a file name). Fortunately, Emacs
                    provides a system for this. In addition, the provided file file
                    e2ansi-magic.el sets up additional file types. For example:



                    Pipe example



                    Why use Emacs?




                    • Emacs has support for virtually all programming languages and
                      structured text formats. In most cases, the syntax highlighting
                      support is excellent.

                    • You can easily add support for more languages and formats, or modify
                      existing packages to suit you needs.

                    • Emacs support color themes. When using e2ansi, the colors in the
                      theme is preserved when viewing a file in less. You can pick a
                      suitable color theme from a number of sources, or design your own.

                    • If you use Emacs as your editor of choice, you will get the same
                      highlighting in the editor as you get when viewing a file using
                      less (minus limitations in ANSI sequence format and the terminal
                      window).


                    • less will take advantage of Emacs features that perform automatic
                      conversion, for example uncompressing files. In fact, you can teach
                      Emacs to perform any kind of conversion like automatically convert a
                      binary file to human readable form using an external tool.

                    • You can view files located on other machines by using Emacs' syntax
                      for remote access like /USER@HOST:FILENAME.


                    Useful links





                    • e2ansi is distributed on Melpa and can be installed using
                      the standard Emacs package system


                    • e2ansi is hosted on GitHub

                    • The e2ansi page on the Emacs Wiki

                    • The home of less.


                    Operating system notes




                    • On MS Windows, the console does not natively support ANSI sequences.
                      Fortunately, the less application is capable of rendering them. I
                      am not aware of any contemporary binary distribution of less for
                      MS Windows and the provided build files is hard to use. Fortunately,
                      it's easy to build less using CMake, see this text for
                      details.


                    • OS X distributes an ancient version of less. Fortunately, it's
                      easy to build a modern version directly from the source.







                    share|improve this answer
























                    • For OS X, I'd recommend using the package manager brew [brew.sh/] with brew dupes [github.com/Homebrew/homebrew-dupes] to install up-to-date versions of things like less.

                      – drevicko
                      Jan 26 '16 at 10:53













                    • "powered by emacs" -- running whole VM just to look at a file? ;-) and +1

                      – Alois Mahdal
                      Oct 19 '17 at 23:58


















                    8














                    I'm glad to announce a new package, e2ansi, that provides
                    syntax highlighting support for pagers like more and less.



                    The package use the mother of all text editors, Emacs, to
                    perform the actual syntax highlighting. As an added bonus, all other
                    conversions normally performed by Emacs -- like uncompressing files --
                    is also performed.



                    Example



                    The following is the result of viewing a file using less and
                    e2ansi:



                    Example



                    Configuration



                    The package provides a command-line tool e2ansi-cat that starts
                    Emacs in batch mode, opens files, syntax highlight them, and renders
                    the result using ANSI sequences.



                    You can integrate this into less by setting the following variables
                    to, for example (the location of your init file may vary):



                    export "LESSOPEN=||-/usr/local/emacs --batch -Q -l ~/.emacs -l bin/e2ansi-cat %s"
                    export "LESS=-r"
                    alias "more=less -X -E"


                    In the configuration above, less restores the original terminal
                    window content whereas more simply output new content after the
                    prompt.



                    Note: If you use an old version of less, it might not support the
                    || or the - syntax, in which case you may need to use simply
                    LESSOPEN=|/usr/local/emacs ....



                    Using less in pipes



                    The "-" character in LESSOPEN indicates that the input filter should
                    also be used when piping text into less. In this case, Emacs can
                    only rely on text itself (and not a file name). Fortunately, Emacs
                    provides a system for this. In addition, the provided file file
                    e2ansi-magic.el sets up additional file types. For example:



                    Pipe example



                    Why use Emacs?




                    • Emacs has support for virtually all programming languages and
                      structured text formats. In most cases, the syntax highlighting
                      support is excellent.

                    • You can easily add support for more languages and formats, or modify
                      existing packages to suit you needs.

                    • Emacs support color themes. When using e2ansi, the colors in the
                      theme is preserved when viewing a file in less. You can pick a
                      suitable color theme from a number of sources, or design your own.

                    • If you use Emacs as your editor of choice, you will get the same
                      highlighting in the editor as you get when viewing a file using
                      less (minus limitations in ANSI sequence format and the terminal
                      window).


                    • less will take advantage of Emacs features that perform automatic
                      conversion, for example uncompressing files. In fact, you can teach
                      Emacs to perform any kind of conversion like automatically convert a
                      binary file to human readable form using an external tool.

                    • You can view files located on other machines by using Emacs' syntax
                      for remote access like /USER@HOST:FILENAME.


                    Useful links





                    • e2ansi is distributed on Melpa and can be installed using
                      the standard Emacs package system


                    • e2ansi is hosted on GitHub

                    • The e2ansi page on the Emacs Wiki

                    • The home of less.


                    Operating system notes




                    • On MS Windows, the console does not natively support ANSI sequences.
                      Fortunately, the less application is capable of rendering them. I
                      am not aware of any contemporary binary distribution of less for
                      MS Windows and the provided build files is hard to use. Fortunately,
                      it's easy to build less using CMake, see this text for
                      details.


                    • OS X distributes an ancient version of less. Fortunately, it's
                      easy to build a modern version directly from the source.







                    share|improve this answer
























                    • For OS X, I'd recommend using the package manager brew [brew.sh/] with brew dupes [github.com/Homebrew/homebrew-dupes] to install up-to-date versions of things like less.

                      – drevicko
                      Jan 26 '16 at 10:53













                    • "powered by emacs" -- running whole VM just to look at a file? ;-) and +1

                      – Alois Mahdal
                      Oct 19 '17 at 23:58
















                    8












                    8








                    8







                    I'm glad to announce a new package, e2ansi, that provides
                    syntax highlighting support for pagers like more and less.



                    The package use the mother of all text editors, Emacs, to
                    perform the actual syntax highlighting. As an added bonus, all other
                    conversions normally performed by Emacs -- like uncompressing files --
                    is also performed.



                    Example



                    The following is the result of viewing a file using less and
                    e2ansi:



                    Example



                    Configuration



                    The package provides a command-line tool e2ansi-cat that starts
                    Emacs in batch mode, opens files, syntax highlight them, and renders
                    the result using ANSI sequences.



                    You can integrate this into less by setting the following variables
                    to, for example (the location of your init file may vary):



                    export "LESSOPEN=||-/usr/local/emacs --batch -Q -l ~/.emacs -l bin/e2ansi-cat %s"
                    export "LESS=-r"
                    alias "more=less -X -E"


                    In the configuration above, less restores the original terminal
                    window content whereas more simply output new content after the
                    prompt.



                    Note: If you use an old version of less, it might not support the
                    || or the - syntax, in which case you may need to use simply
                    LESSOPEN=|/usr/local/emacs ....



                    Using less in pipes



                    The "-" character in LESSOPEN indicates that the input filter should
                    also be used when piping text into less. In this case, Emacs can
                    only rely on text itself (and not a file name). Fortunately, Emacs
                    provides a system for this. In addition, the provided file file
                    e2ansi-magic.el sets up additional file types. For example:



                    Pipe example



                    Why use Emacs?




                    • Emacs has support for virtually all programming languages and
                      structured text formats. In most cases, the syntax highlighting
                      support is excellent.

                    • You can easily add support for more languages and formats, or modify
                      existing packages to suit you needs.

                    • Emacs support color themes. When using e2ansi, the colors in the
                      theme is preserved when viewing a file in less. You can pick a
                      suitable color theme from a number of sources, or design your own.

                    • If you use Emacs as your editor of choice, you will get the same
                      highlighting in the editor as you get when viewing a file using
                      less (minus limitations in ANSI sequence format and the terminal
                      window).


                    • less will take advantage of Emacs features that perform automatic
                      conversion, for example uncompressing files. In fact, you can teach
                      Emacs to perform any kind of conversion like automatically convert a
                      binary file to human readable form using an external tool.

                    • You can view files located on other machines by using Emacs' syntax
                      for remote access like /USER@HOST:FILENAME.


                    Useful links





                    • e2ansi is distributed on Melpa and can be installed using
                      the standard Emacs package system


                    • e2ansi is hosted on GitHub

                    • The e2ansi page on the Emacs Wiki

                    • The home of less.


                    Operating system notes




                    • On MS Windows, the console does not natively support ANSI sequences.
                      Fortunately, the less application is capable of rendering them. I
                      am not aware of any contemporary binary distribution of less for
                      MS Windows and the provided build files is hard to use. Fortunately,
                      it's easy to build less using CMake, see this text for
                      details.


                    • OS X distributes an ancient version of less. Fortunately, it's
                      easy to build a modern version directly from the source.







                    share|improve this answer













                    I'm glad to announce a new package, e2ansi, that provides
                    syntax highlighting support for pagers like more and less.



                    The package use the mother of all text editors, Emacs, to
                    perform the actual syntax highlighting. As an added bonus, all other
                    conversions normally performed by Emacs -- like uncompressing files --
                    is also performed.



                    Example



                    The following is the result of viewing a file using less and
                    e2ansi:



                    Example



                    Configuration



                    The package provides a command-line tool e2ansi-cat that starts
                    Emacs in batch mode, opens files, syntax highlight them, and renders
                    the result using ANSI sequences.



                    You can integrate this into less by setting the following variables
                    to, for example (the location of your init file may vary):



                    export "LESSOPEN=||-/usr/local/emacs --batch -Q -l ~/.emacs -l bin/e2ansi-cat %s"
                    export "LESS=-r"
                    alias "more=less -X -E"


                    In the configuration above, less restores the original terminal
                    window content whereas more simply output new content after the
                    prompt.



                    Note: If you use an old version of less, it might not support the
                    || or the - syntax, in which case you may need to use simply
                    LESSOPEN=|/usr/local/emacs ....



                    Using less in pipes



                    The "-" character in LESSOPEN indicates that the input filter should
                    also be used when piping text into less. In this case, Emacs can
                    only rely on text itself (and not a file name). Fortunately, Emacs
                    provides a system for this. In addition, the provided file file
                    e2ansi-magic.el sets up additional file types. For example:



                    Pipe example



                    Why use Emacs?




                    • Emacs has support for virtually all programming languages and
                      structured text formats. In most cases, the syntax highlighting
                      support is excellent.

                    • You can easily add support for more languages and formats, or modify
                      existing packages to suit you needs.

                    • Emacs support color themes. When using e2ansi, the colors in the
                      theme is preserved when viewing a file in less. You can pick a
                      suitable color theme from a number of sources, or design your own.

                    • If you use Emacs as your editor of choice, you will get the same
                      highlighting in the editor as you get when viewing a file using
                      less (minus limitations in ANSI sequence format and the terminal
                      window).


                    • less will take advantage of Emacs features that perform automatic
                      conversion, for example uncompressing files. In fact, you can teach
                      Emacs to perform any kind of conversion like automatically convert a
                      binary file to human readable form using an external tool.

                    • You can view files located on other machines by using Emacs' syntax
                      for remote access like /USER@HOST:FILENAME.


                    Useful links





                    • e2ansi is distributed on Melpa and can be installed using
                      the standard Emacs package system


                    • e2ansi is hosted on GitHub

                    • The e2ansi page on the Emacs Wiki

                    • The home of less.


                    Operating system notes




                    • On MS Windows, the console does not natively support ANSI sequences.
                      Fortunately, the less application is capable of rendering them. I
                      am not aware of any contemporary binary distribution of less for
                      MS Windows and the provided build files is hard to use. Fortunately,
                      it's easy to build less using CMake, see this text for
                      details.


                    • OS X distributes an ancient version of less. Fortunately, it's
                      easy to build a modern version directly from the source.








                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Feb 4 '15 at 19:10









                    LindydancerLindydancer

                    19914




                    19914













                    • For OS X, I'd recommend using the package manager brew [brew.sh/] with brew dupes [github.com/Homebrew/homebrew-dupes] to install up-to-date versions of things like less.

                      – drevicko
                      Jan 26 '16 at 10:53













                    • "powered by emacs" -- running whole VM just to look at a file? ;-) and +1

                      – Alois Mahdal
                      Oct 19 '17 at 23:58





















                    • For OS X, I'd recommend using the package manager brew [brew.sh/] with brew dupes [github.com/Homebrew/homebrew-dupes] to install up-to-date versions of things like less.

                      – drevicko
                      Jan 26 '16 at 10:53













                    • "powered by emacs" -- running whole VM just to look at a file? ;-) and +1

                      – Alois Mahdal
                      Oct 19 '17 at 23:58



















                    For OS X, I'd recommend using the package manager brew [brew.sh/] with brew dupes [github.com/Homebrew/homebrew-dupes] to install up-to-date versions of things like less.

                    – drevicko
                    Jan 26 '16 at 10:53







                    For OS X, I'd recommend using the package manager brew [brew.sh/] with brew dupes [github.com/Homebrew/homebrew-dupes] to install up-to-date versions of things like less.

                    – drevicko
                    Jan 26 '16 at 10:53















                    "powered by emacs" -- running whole VM just to look at a file? ;-) and +1

                    – Alois Mahdal
                    Oct 19 '17 at 23:58







                    "powered by emacs" -- running whole VM just to look at a file? ;-) and +1

                    – Alois Mahdal
                    Oct 19 '17 at 23:58













                    6














                    If you have GNU Source-highlight installed you can use the following command to highlight the syntax of a single file:



                    $ src-hilite-lesspipe.sh yourfile.xml | less -R





                    share|improve this answer
























                    • Can src-hilite-lesspipe.sh receive input via a pipe as well?

                      – waldyrious
                      Dec 27 '16 at 12:42
















                    6














                    If you have GNU Source-highlight installed you can use the following command to highlight the syntax of a single file:



                    $ src-hilite-lesspipe.sh yourfile.xml | less -R





                    share|improve this answer
























                    • Can src-hilite-lesspipe.sh receive input via a pipe as well?

                      – waldyrious
                      Dec 27 '16 at 12:42














                    6












                    6








                    6







                    If you have GNU Source-highlight installed you can use the following command to highlight the syntax of a single file:



                    $ src-hilite-lesspipe.sh yourfile.xml | less -R





                    share|improve this answer













                    If you have GNU Source-highlight installed you can use the following command to highlight the syntax of a single file:



                    $ src-hilite-lesspipe.sh yourfile.xml | less -R






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 7 '12 at 7:52









                    OliverOliver

                    16112




                    16112













                    • Can src-hilite-lesspipe.sh receive input via a pipe as well?

                      – waldyrious
                      Dec 27 '16 at 12:42



















                    • Can src-hilite-lesspipe.sh receive input via a pipe as well?

                      – waldyrious
                      Dec 27 '16 at 12:42

















                    Can src-hilite-lesspipe.sh receive input via a pipe as well?

                    – waldyrious
                    Dec 27 '16 at 12:42





                    Can src-hilite-lesspipe.sh receive input via a pipe as well?

                    – waldyrious
                    Dec 27 '16 at 12:42











                    2














                    source-highlight has a .sh script located in /usr/share/source-highlight/*.sh. I've created a symbolic link to it with name hcat in /usr/bin.



                    It shows highlighted output in terminal (console) – hcat is highlighted cat.



                    How to:



                    [me@this]<bash><~> 43 
                    21:23 Fri Apr 19 > sudo apt-get install source-highlight

                    [me@this]<bash><~> 28
                    21:03 Fri Apr 19 > ll /usr/share/source-highlight/*.sh
                    -rwxr-xr-x 1 root root 432 May 1 2012 /usr/share/source-highlight/src-hilite-lesspipe.sh*

                    [me@this]<bash><~> 29
                    21:04 Fri Apr 19 > sudo su
                    root@this:/home/me# cd /usr/bin/
                    root@this:/usr/bin# ln -s /usr/share/source-highlight/src-hilite-lesspipe.sh hcat

                    [me@this]<bash><~> 36
                    21:07 Fri Apr 19 > hcat test.xml





                    share|improve this answer






























                      2














                      source-highlight has a .sh script located in /usr/share/source-highlight/*.sh. I've created a symbolic link to it with name hcat in /usr/bin.



                      It shows highlighted output in terminal (console) – hcat is highlighted cat.



                      How to:



                      [me@this]<bash><~> 43 
                      21:23 Fri Apr 19 > sudo apt-get install source-highlight

                      [me@this]<bash><~> 28
                      21:03 Fri Apr 19 > ll /usr/share/source-highlight/*.sh
                      -rwxr-xr-x 1 root root 432 May 1 2012 /usr/share/source-highlight/src-hilite-lesspipe.sh*

                      [me@this]<bash><~> 29
                      21:04 Fri Apr 19 > sudo su
                      root@this:/home/me# cd /usr/bin/
                      root@this:/usr/bin# ln -s /usr/share/source-highlight/src-hilite-lesspipe.sh hcat

                      [me@this]<bash><~> 36
                      21:07 Fri Apr 19 > hcat test.xml





                      share|improve this answer




























                        2












                        2








                        2







                        source-highlight has a .sh script located in /usr/share/source-highlight/*.sh. I've created a symbolic link to it with name hcat in /usr/bin.



                        It shows highlighted output in terminal (console) – hcat is highlighted cat.



                        How to:



                        [me@this]<bash><~> 43 
                        21:23 Fri Apr 19 > sudo apt-get install source-highlight

                        [me@this]<bash><~> 28
                        21:03 Fri Apr 19 > ll /usr/share/source-highlight/*.sh
                        -rwxr-xr-x 1 root root 432 May 1 2012 /usr/share/source-highlight/src-hilite-lesspipe.sh*

                        [me@this]<bash><~> 29
                        21:04 Fri Apr 19 > sudo su
                        root@this:/home/me# cd /usr/bin/
                        root@this:/usr/bin# ln -s /usr/share/source-highlight/src-hilite-lesspipe.sh hcat

                        [me@this]<bash><~> 36
                        21:07 Fri Apr 19 > hcat test.xml





                        share|improve this answer















                        source-highlight has a .sh script located in /usr/share/source-highlight/*.sh. I've created a symbolic link to it with name hcat in /usr/bin.



                        It shows highlighted output in terminal (console) – hcat is highlighted cat.



                        How to:



                        [me@this]<bash><~> 43 
                        21:23 Fri Apr 19 > sudo apt-get install source-highlight

                        [me@this]<bash><~> 28
                        21:03 Fri Apr 19 > ll /usr/share/source-highlight/*.sh
                        -rwxr-xr-x 1 root root 432 May 1 2012 /usr/share/source-highlight/src-hilite-lesspipe.sh*

                        [me@this]<bash><~> 29
                        21:04 Fri Apr 19 > sudo su
                        root@this:/home/me# cd /usr/bin/
                        root@this:/usr/bin# ln -s /usr/share/source-highlight/src-hilite-lesspipe.sh hcat

                        [me@this]<bash><~> 36
                        21:07 Fri Apr 19 > hcat test.xml






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Sep 10 '13 at 7:39









                        slhck

                        164k47452477




                        164k47452477










                        answered Apr 19 '13 at 18:25









                        Vitalie GhelbertVitalie Ghelbert

                        1314




                        1314























                            2














                            Using OS X 10.9 (Maverick) this would do the trick:




                            • brew install source-highlight (Assuming brew is installed - http://brew.sh)


                            • sudo nano /etc/launchd.conf




                              setenv LESSOPEN="| /usr/local/bin/src-hilite-lesspipe.sh %s"     
                              setenv LESS=' -R '



                              (Add to /etc/launchd.conf)



                            • reboot







                            share|improve this answer




























                              2














                              Using OS X 10.9 (Maverick) this would do the trick:




                              • brew install source-highlight (Assuming brew is installed - http://brew.sh)


                              • sudo nano /etc/launchd.conf




                                setenv LESSOPEN="| /usr/local/bin/src-hilite-lesspipe.sh %s"     
                                setenv LESS=' -R '



                                (Add to /etc/launchd.conf)



                              • reboot







                              share|improve this answer


























                                2












                                2








                                2







                                Using OS X 10.9 (Maverick) this would do the trick:




                                • brew install source-highlight (Assuming brew is installed - http://brew.sh)


                                • sudo nano /etc/launchd.conf




                                  setenv LESSOPEN="| /usr/local/bin/src-hilite-lesspipe.sh %s"     
                                  setenv LESS=' -R '



                                  (Add to /etc/launchd.conf)



                                • reboot







                                share|improve this answer













                                Using OS X 10.9 (Maverick) this would do the trick:




                                • brew install source-highlight (Assuming brew is installed - http://brew.sh)


                                • sudo nano /etc/launchd.conf




                                  setenv LESSOPEN="| /usr/local/bin/src-hilite-lesspipe.sh %s"     
                                  setenv LESS=' -R '



                                  (Add to /etc/launchd.conf)



                                • reboot








                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Apr 7 '14 at 19:21









                                TeNGiLTeNGiL

                                212




                                212























                                    0














                                    In mac, you can just type view filename, does similar thing like less.






                                    share|improve this answer



















                                    • 1





                                      With OSX, view filename just launches vim by default - slightly different key bindings to less (see other answers to this question for more details).

                                      – drevicko
                                      Jan 26 '16 at 10:56


















                                    0














                                    In mac, you can just type view filename, does similar thing like less.






                                    share|improve this answer



















                                    • 1





                                      With OSX, view filename just launches vim by default - slightly different key bindings to less (see other answers to this question for more details).

                                      – drevicko
                                      Jan 26 '16 at 10:56
















                                    0












                                    0








                                    0







                                    In mac, you can just type view filename, does similar thing like less.






                                    share|improve this answer













                                    In mac, you can just type view filename, does similar thing like less.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Jul 14 '14 at 14:12









                                    Alan DongAlan Dong

                                    1436




                                    1436








                                    • 1





                                      With OSX, view filename just launches vim by default - slightly different key bindings to less (see other answers to this question for more details).

                                      – drevicko
                                      Jan 26 '16 at 10:56
















                                    • 1





                                      With OSX, view filename just launches vim by default - slightly different key bindings to less (see other answers to this question for more details).

                                      – drevicko
                                      Jan 26 '16 at 10:56










                                    1




                                    1





                                    With OSX, view filename just launches vim by default - slightly different key bindings to less (see other answers to this question for more details).

                                    – drevicko
                                    Jan 26 '16 at 10:56







                                    With OSX, view filename just launches vim by default - slightly different key bindings to less (see other answers to this question for more details).

                                    – drevicko
                                    Jan 26 '16 at 10:56













                                    0














                                    After installing GNU's source-highlight (package dev-util/source-highlight on sabayon/gentoo), I configured those envs in /etc/bash/bashrc.d/my-less-src-highlight:



                                    #default:    export LESSOPEN="|lesspipe %s"
                                    #don't like: export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s"
                                    #default: export LESS=" -R -M --shift 5"
                                    export LESSCOLOR=always
                                    export LESSCOLORIZER=/usr/bin/src-hilite-lesspipe.sh


                                    I did not like to replace lesspipe because that has other features. Concatenation did not work.






                                    share|improve this answer




























                                      0














                                      After installing GNU's source-highlight (package dev-util/source-highlight on sabayon/gentoo), I configured those envs in /etc/bash/bashrc.d/my-less-src-highlight:



                                      #default:    export LESSOPEN="|lesspipe %s"
                                      #don't like: export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s"
                                      #default: export LESS=" -R -M --shift 5"
                                      export LESSCOLOR=always
                                      export LESSCOLORIZER=/usr/bin/src-hilite-lesspipe.sh


                                      I did not like to replace lesspipe because that has other features. Concatenation did not work.






                                      share|improve this answer


























                                        0












                                        0








                                        0







                                        After installing GNU's source-highlight (package dev-util/source-highlight on sabayon/gentoo), I configured those envs in /etc/bash/bashrc.d/my-less-src-highlight:



                                        #default:    export LESSOPEN="|lesspipe %s"
                                        #don't like: export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s"
                                        #default: export LESS=" -R -M --shift 5"
                                        export LESSCOLOR=always
                                        export LESSCOLORIZER=/usr/bin/src-hilite-lesspipe.sh


                                        I did not like to replace lesspipe because that has other features. Concatenation did not work.






                                        share|improve this answer













                                        After installing GNU's source-highlight (package dev-util/source-highlight on sabayon/gentoo), I configured those envs in /etc/bash/bashrc.d/my-less-src-highlight:



                                        #default:    export LESSOPEN="|lesspipe %s"
                                        #don't like: export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s"
                                        #default: export LESS=" -R -M --shift 5"
                                        export LESSCOLOR=always
                                        export LESSCOLORIZER=/usr/bin/src-hilite-lesspipe.sh


                                        I did not like to replace lesspipe because that has other features. Concatenation did not work.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Mar 24 '15 at 13:27









                                        comonadcomonad

                                        1012




                                        1012























                                            0














                                            If you want the same syntax highlighting you use in Vim, but for some reason you prefer to use less as your pager, you can use this script: https://github.com/rkitover/vimpager



                                            The basic usage would be:



                                            vimpager file.txt


                                            or



                                            vimcat file.ext | less -R


                                            You can use -c to pass extra commands which aren't in your .vimrc (e.g. selecting a different colorscheme). The full command I use is:



                                            vimcat -c 'set cmdheight=20' -c 'hi! clear Normal' -o - "$FILENAME" | less -REXS


                                            Beware: If your Vim asks you to press Enter when it starts up, you won't see the prompt, but nothing will happen until you press Enter! The cmdheight trick above can help to mitigate that.






                                            share|improve this answer




























                                              0














                                              If you want the same syntax highlighting you use in Vim, but for some reason you prefer to use less as your pager, you can use this script: https://github.com/rkitover/vimpager



                                              The basic usage would be:



                                              vimpager file.txt


                                              or



                                              vimcat file.ext | less -R


                                              You can use -c to pass extra commands which aren't in your .vimrc (e.g. selecting a different colorscheme). The full command I use is:



                                              vimcat -c 'set cmdheight=20' -c 'hi! clear Normal' -o - "$FILENAME" | less -REXS


                                              Beware: If your Vim asks you to press Enter when it starts up, you won't see the prompt, but nothing will happen until you press Enter! The cmdheight trick above can help to mitigate that.






                                              share|improve this answer


























                                                0












                                                0








                                                0







                                                If you want the same syntax highlighting you use in Vim, but for some reason you prefer to use less as your pager, you can use this script: https://github.com/rkitover/vimpager



                                                The basic usage would be:



                                                vimpager file.txt


                                                or



                                                vimcat file.ext | less -R


                                                You can use -c to pass extra commands which aren't in your .vimrc (e.g. selecting a different colorscheme). The full command I use is:



                                                vimcat -c 'set cmdheight=20' -c 'hi! clear Normal' -o - "$FILENAME" | less -REXS


                                                Beware: If your Vim asks you to press Enter when it starts up, you won't see the prompt, but nothing will happen until you press Enter! The cmdheight trick above can help to mitigate that.






                                                share|improve this answer













                                                If you want the same syntax highlighting you use in Vim, but for some reason you prefer to use less as your pager, you can use this script: https://github.com/rkitover/vimpager



                                                The basic usage would be:



                                                vimpager file.txt


                                                or



                                                vimcat file.ext | less -R


                                                You can use -c to pass extra commands which aren't in your .vimrc (e.g. selecting a different colorscheme). The full command I use is:



                                                vimcat -c 'set cmdheight=20' -c 'hi! clear Normal' -o - "$FILENAME" | less -REXS


                                                Beware: If your Vim asks you to press Enter when it starts up, you won't see the prompt, but nothing will happen until you press Enter! The cmdheight trick above can help to mitigate that.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Feb 3 '18 at 16:01









                                                joeytwiddlejoeytwiddle

                                                1,11611216




                                                1,11611216























                                                    0














                                                    I found highlight which:




                                                    • Supports multiple colour schemes and 256-colours

                                                    • Works on STDIN (unlike source-highlight)

                                                    • Is much faster than pygmentize


                                                    Screenshot



                                                    Here is a script I call highlight-less-wrapper which includes .bashrc instructions on how to setup less to use it automatically.



                                                    #!/bin/bash

                                                    # Have highlight read from STDIN if '-' is given as filename

                                                    # Setup - Add to .bashrc:
                                                    # LESSOPEN='|-highlight-less-wrapper "%s"'
                                                    # export LESS=-FMRXis

                                                    # Usage:
                                                    # $ less file
                                                    # OR
                                                    # $ pipeline | less

                                                    warn () { printf "%s: %sn" "$(basename "$0")" "$*" 1>&2; }
                                                    die () { warn "$@"; exit 1; }

                                                    # Argument checking
                                                    case $# in
                                                    0)
                                                    # Allow `exec $0` for less setup
                                                    echo "LESSOPEN='|-$(readlink -f "$0") "'"%s"''
                                                    exit 255 ;;
                                                    1)
                                                    # Only one argument is expected.
                                                    # less will invoke multiple times given multiple files.
                                                    file=$1
                                                    if [[ $file != - && ! -r $file ]]; then # less passes '-' for STDIN
                                                    die "Cannot open $file for reading"
                                                    fi ;;
                                                    *)
                                                    die "Expected only one argument" ;;
                                                    esac

                                                    # Run highlight
                                                    # highlight will read from STDIN when given a null filename
                                                    run_highlight () {
                                                    highlight --force -O truecolor --style aiseered "$1"
                                                    }

                                                    if [[ $file == - ]]; then # Run on stdin
                                                    run_highlight ""
                                                    else
                                                    run_highlight "$file"
                                                    fi





                                                    share|improve this answer


























                                                    • "Since Github is now part of Mordor Corp, the highlight Git repo moved" Was interested, but cmon it's not the 90's anymore devs need to grow up.

                                                      – Urda
                                                      Oct 2 '18 at 19:15


















                                                    0














                                                    I found highlight which:




                                                    • Supports multiple colour schemes and 256-colours

                                                    • Works on STDIN (unlike source-highlight)

                                                    • Is much faster than pygmentize


                                                    Screenshot



                                                    Here is a script I call highlight-less-wrapper which includes .bashrc instructions on how to setup less to use it automatically.



                                                    #!/bin/bash

                                                    # Have highlight read from STDIN if '-' is given as filename

                                                    # Setup - Add to .bashrc:
                                                    # LESSOPEN='|-highlight-less-wrapper "%s"'
                                                    # export LESS=-FMRXis

                                                    # Usage:
                                                    # $ less file
                                                    # OR
                                                    # $ pipeline | less

                                                    warn () { printf "%s: %sn" "$(basename "$0")" "$*" 1>&2; }
                                                    die () { warn "$@"; exit 1; }

                                                    # Argument checking
                                                    case $# in
                                                    0)
                                                    # Allow `exec $0` for less setup
                                                    echo "LESSOPEN='|-$(readlink -f "$0") "'"%s"''
                                                    exit 255 ;;
                                                    1)
                                                    # Only one argument is expected.
                                                    # less will invoke multiple times given multiple files.
                                                    file=$1
                                                    if [[ $file != - && ! -r $file ]]; then # less passes '-' for STDIN
                                                    die "Cannot open $file for reading"
                                                    fi ;;
                                                    *)
                                                    die "Expected only one argument" ;;
                                                    esac

                                                    # Run highlight
                                                    # highlight will read from STDIN when given a null filename
                                                    run_highlight () {
                                                    highlight --force -O truecolor --style aiseered "$1"
                                                    }

                                                    if [[ $file == - ]]; then # Run on stdin
                                                    run_highlight ""
                                                    else
                                                    run_highlight "$file"
                                                    fi





                                                    share|improve this answer


























                                                    • "Since Github is now part of Mordor Corp, the highlight Git repo moved" Was interested, but cmon it's not the 90's anymore devs need to grow up.

                                                      – Urda
                                                      Oct 2 '18 at 19:15
















                                                    0












                                                    0








                                                    0







                                                    I found highlight which:




                                                    • Supports multiple colour schemes and 256-colours

                                                    • Works on STDIN (unlike source-highlight)

                                                    • Is much faster than pygmentize


                                                    Screenshot



                                                    Here is a script I call highlight-less-wrapper which includes .bashrc instructions on how to setup less to use it automatically.



                                                    #!/bin/bash

                                                    # Have highlight read from STDIN if '-' is given as filename

                                                    # Setup - Add to .bashrc:
                                                    # LESSOPEN='|-highlight-less-wrapper "%s"'
                                                    # export LESS=-FMRXis

                                                    # Usage:
                                                    # $ less file
                                                    # OR
                                                    # $ pipeline | less

                                                    warn () { printf "%s: %sn" "$(basename "$0")" "$*" 1>&2; }
                                                    die () { warn "$@"; exit 1; }

                                                    # Argument checking
                                                    case $# in
                                                    0)
                                                    # Allow `exec $0` for less setup
                                                    echo "LESSOPEN='|-$(readlink -f "$0") "'"%s"''
                                                    exit 255 ;;
                                                    1)
                                                    # Only one argument is expected.
                                                    # less will invoke multiple times given multiple files.
                                                    file=$1
                                                    if [[ $file != - && ! -r $file ]]; then # less passes '-' for STDIN
                                                    die "Cannot open $file for reading"
                                                    fi ;;
                                                    *)
                                                    die "Expected only one argument" ;;
                                                    esac

                                                    # Run highlight
                                                    # highlight will read from STDIN when given a null filename
                                                    run_highlight () {
                                                    highlight --force -O truecolor --style aiseered "$1"
                                                    }

                                                    if [[ $file == - ]]; then # Run on stdin
                                                    run_highlight ""
                                                    else
                                                    run_highlight "$file"
                                                    fi





                                                    share|improve this answer















                                                    I found highlight which:




                                                    • Supports multiple colour schemes and 256-colours

                                                    • Works on STDIN (unlike source-highlight)

                                                    • Is much faster than pygmentize


                                                    Screenshot



                                                    Here is a script I call highlight-less-wrapper which includes .bashrc instructions on how to setup less to use it automatically.



                                                    #!/bin/bash

                                                    # Have highlight read from STDIN if '-' is given as filename

                                                    # Setup - Add to .bashrc:
                                                    # LESSOPEN='|-highlight-less-wrapper "%s"'
                                                    # export LESS=-FMRXis

                                                    # Usage:
                                                    # $ less file
                                                    # OR
                                                    # $ pipeline | less

                                                    warn () { printf "%s: %sn" "$(basename "$0")" "$*" 1>&2; }
                                                    die () { warn "$@"; exit 1; }

                                                    # Argument checking
                                                    case $# in
                                                    0)
                                                    # Allow `exec $0` for less setup
                                                    echo "LESSOPEN='|-$(readlink -f "$0") "'"%s"''
                                                    exit 255 ;;
                                                    1)
                                                    # Only one argument is expected.
                                                    # less will invoke multiple times given multiple files.
                                                    file=$1
                                                    if [[ $file != - && ! -r $file ]]; then # less passes '-' for STDIN
                                                    die "Cannot open $file for reading"
                                                    fi ;;
                                                    *)
                                                    die "Expected only one argument" ;;
                                                    esac

                                                    # Run highlight
                                                    # highlight will read from STDIN when given a null filename
                                                    run_highlight () {
                                                    highlight --force -O truecolor --style aiseered "$1"
                                                    }

                                                    if [[ $file == - ]]; then # Run on stdin
                                                    run_highlight ""
                                                    else
                                                    run_highlight "$file"
                                                    fi






                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Jun 17 '18 at 16:54

























                                                    answered Jun 17 '18 at 15:50









                                                    Tom HaleTom Hale

                                                    897822




                                                    897822













                                                    • "Since Github is now part of Mordor Corp, the highlight Git repo moved" Was interested, but cmon it's not the 90's anymore devs need to grow up.

                                                      – Urda
                                                      Oct 2 '18 at 19:15





















                                                    • "Since Github is now part of Mordor Corp, the highlight Git repo moved" Was interested, but cmon it's not the 90's anymore devs need to grow up.

                                                      – Urda
                                                      Oct 2 '18 at 19:15



















                                                    "Since Github is now part of Mordor Corp, the highlight Git repo moved" Was interested, but cmon it's not the 90's anymore devs need to grow up.

                                                    – Urda
                                                    Oct 2 '18 at 19:15







                                                    "Since Github is now part of Mordor Corp, the highlight Git repo moved" Was interested, but cmon it's not the 90's anymore devs need to grow up.

                                                    – Urda
                                                    Oct 2 '18 at 19:15













                                                    0














                                                    I had the same question and I landed hear, read all answers and the following is what I finally did to have syntax highlighting everytime I use less or most:



                                                    sudo apt install source-highlight


                                                    Then I went and created an alias for my less and most (I use ZSH, but you can add aliases for your .bashrc file if you use bash):



                                                    vim ~/.zshrc


                                                    (For those who might get stuck in vim: press i to go to edit mode, when you are done press Esc then : then x and finally
                                                    Enter to save the changes
                                                    )



                                                    And paste the following lines for debian-based distros (like Debian, Ubuntu, Mint, etc.):



                                                    alias most='AliasFuncLess() { unset -f AliasFuncLess; $(dpkg -L libsource-highlight-common | grep lesspipe) "$1" | less -R };AliasFuncLess'
                                                    alias most='AliasFuncMost() { unset -f AliasFuncMost; $(dpkg -L libsource-highlight-common | grep lesspipe) "$1" | most };AliasFuncMost'


                                                    or for RPM distros (Redhat, Fedora, Centos):



                                                    alias most='AliasFuncLess() { unset -f AliasFuncLess; $(rpm -ql source-highlight | grep lesspipe) "$1" | less -R };AliasFuncLess'
                                                    alias most='AliasFuncMost() { unset -f AliasFuncMost; $(rpm -ql source-highlight | grep lesspipe) "$1" | most };AliasFuncMost'


                                                    Remember to close the terminal and open it again to make sure alias is created.



                                                    Now you can enjoy the colors:



                                                    most yourFile.xml





                                                    share|improve this answer






























                                                      0














                                                      I had the same question and I landed hear, read all answers and the following is what I finally did to have syntax highlighting everytime I use less or most:



                                                      sudo apt install source-highlight


                                                      Then I went and created an alias for my less and most (I use ZSH, but you can add aliases for your .bashrc file if you use bash):



                                                      vim ~/.zshrc


                                                      (For those who might get stuck in vim: press i to go to edit mode, when you are done press Esc then : then x and finally
                                                      Enter to save the changes
                                                      )



                                                      And paste the following lines for debian-based distros (like Debian, Ubuntu, Mint, etc.):



                                                      alias most='AliasFuncLess() { unset -f AliasFuncLess; $(dpkg -L libsource-highlight-common | grep lesspipe) "$1" | less -R };AliasFuncLess'
                                                      alias most='AliasFuncMost() { unset -f AliasFuncMost; $(dpkg -L libsource-highlight-common | grep lesspipe) "$1" | most };AliasFuncMost'


                                                      or for RPM distros (Redhat, Fedora, Centos):



                                                      alias most='AliasFuncLess() { unset -f AliasFuncLess; $(rpm -ql source-highlight | grep lesspipe) "$1" | less -R };AliasFuncLess'
                                                      alias most='AliasFuncMost() { unset -f AliasFuncMost; $(rpm -ql source-highlight | grep lesspipe) "$1" | most };AliasFuncMost'


                                                      Remember to close the terminal and open it again to make sure alias is created.



                                                      Now you can enjoy the colors:



                                                      most yourFile.xml





                                                      share|improve this answer




























                                                        0












                                                        0








                                                        0







                                                        I had the same question and I landed hear, read all answers and the following is what I finally did to have syntax highlighting everytime I use less or most:



                                                        sudo apt install source-highlight


                                                        Then I went and created an alias for my less and most (I use ZSH, but you can add aliases for your .bashrc file if you use bash):



                                                        vim ~/.zshrc


                                                        (For those who might get stuck in vim: press i to go to edit mode, when you are done press Esc then : then x and finally
                                                        Enter to save the changes
                                                        )



                                                        And paste the following lines for debian-based distros (like Debian, Ubuntu, Mint, etc.):



                                                        alias most='AliasFuncLess() { unset -f AliasFuncLess; $(dpkg -L libsource-highlight-common | grep lesspipe) "$1" | less -R };AliasFuncLess'
                                                        alias most='AliasFuncMost() { unset -f AliasFuncMost; $(dpkg -L libsource-highlight-common | grep lesspipe) "$1" | most };AliasFuncMost'


                                                        or for RPM distros (Redhat, Fedora, Centos):



                                                        alias most='AliasFuncLess() { unset -f AliasFuncLess; $(rpm -ql source-highlight | grep lesspipe) "$1" | less -R };AliasFuncLess'
                                                        alias most='AliasFuncMost() { unset -f AliasFuncMost; $(rpm -ql source-highlight | grep lesspipe) "$1" | most };AliasFuncMost'


                                                        Remember to close the terminal and open it again to make sure alias is created.



                                                        Now you can enjoy the colors:



                                                        most yourFile.xml





                                                        share|improve this answer















                                                        I had the same question and I landed hear, read all answers and the following is what I finally did to have syntax highlighting everytime I use less or most:



                                                        sudo apt install source-highlight


                                                        Then I went and created an alias for my less and most (I use ZSH, but you can add aliases for your .bashrc file if you use bash):



                                                        vim ~/.zshrc


                                                        (For those who might get stuck in vim: press i to go to edit mode, when you are done press Esc then : then x and finally
                                                        Enter to save the changes
                                                        )



                                                        And paste the following lines for debian-based distros (like Debian, Ubuntu, Mint, etc.):



                                                        alias most='AliasFuncLess() { unset -f AliasFuncLess; $(dpkg -L libsource-highlight-common | grep lesspipe) "$1" | less -R };AliasFuncLess'
                                                        alias most='AliasFuncMost() { unset -f AliasFuncMost; $(dpkg -L libsource-highlight-common | grep lesspipe) "$1" | most };AliasFuncMost'


                                                        or for RPM distros (Redhat, Fedora, Centos):



                                                        alias most='AliasFuncLess() { unset -f AliasFuncLess; $(rpm -ql source-highlight | grep lesspipe) "$1" | less -R };AliasFuncLess'
                                                        alias most='AliasFuncMost() { unset -f AliasFuncMost; $(rpm -ql source-highlight | grep lesspipe) "$1" | most };AliasFuncMost'


                                                        Remember to close the terminal and open it again to make sure alias is created.



                                                        Now you can enjoy the colors:



                                                        most yourFile.xml






                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited Sep 5 '18 at 8:09

























                                                        answered Sep 5 '18 at 7:56









                                                        Mehrad MahmoudianMehrad Mahmoudian

                                                        1455




                                                        1455






























                                                            draft saved

                                                            draft discarded




















































                                                            Thanks for contributing an answer to Super User!


                                                            • Please be sure to answer the question. Provide details and share your research!

                                                            But avoid



                                                            • Asking for help, clarification, or responding to other answers.

                                                            • Making statements based on opinion; back them up with references or personal experience.


                                                            To learn more, see our tips on writing great answers.




                                                            draft saved


                                                            draft discarded














                                                            StackExchange.ready(
                                                            function () {
                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f71588%2fhow-to-syntax-highlight-via-less%23new-answer', 'question_page');
                                                            }
                                                            );

                                                            Post as a guest















                                                            Required, but never shown





















































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown

































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown







                                                            Popular posts from this blog

                                                            VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

                                                            Tribunal Administrativo e Fiscal de Mirandela Referências Menu de...

                                                            looking for continuous Screen Capture for retroactivly reproducing errors, timeback machineRolling desktop...