It has been some time since I’ve done a Vim Tip of the Week, but I came across something today that I thought I would share.  This tip will allow you to use Vim, with all its syntax highlighting glory, as a pager (similar to less or more).

If you use cat or less or more regularly to quickly view files, but you’d like to keep the same syntax highlighting that you’d get in Vim you can use an included config that makes Vim act as a pager.  Setup the following within your .bashrc file, or wherever you keep your shell aliases:

alias vless='vim -u /usr/share/vim/vim71/macros/less.vim'

You’ll then need to re-read that file, which can be done using:

. .bashrc

At this point you can use vless to view a file, which will use the beloved syntax highlighting.  Normal pager shortcuts should work.  q to quit, / to search, pg-up, pg-dn, etc.

If this site has been useful, please consider participating in the Fundraiser.

Other Points of Interest

  • No Related Post

Comments

13 Responses to “Use Vim As A Syntax Highlighting Pager”

  1. Charles on July 14th, 2008 6:37 pm

    Great tip! It’s just been added to my aliases.

  2. John M. Anderson on July 14th, 2008 10:53 pm

    Also, if you are in less, you can invoke your $EDITOR by hitting ‘v’

  3. Onkar on July 15th, 2008 12:56 am

    Great tip. I am now going to share it with my colleagues. :-)

    By the way, you should recommend adding aliases to ~/.bash_aliases and uncomment the part in ~/.bashrc that includes the aliases file.

  4. Fabian Neumann on July 15th, 2008 3:05 am

    The is also a script in vims package (at least in Ubuntu) to start it in less mode. So, what I did is:

    ln -s /usr/share/vim/vim71/macros/less.sh ~/bin/vless

  5. Fabian Neumann on July 15th, 2008 3:22 am

    Thanks for the tip just added it to my aliases.

    If someone is looking for a way to use it with pipes just add - at the end to read from stdin instead of a filename.

    example

    svn diff | vless -

  6. Johan Nilsson on July 15th, 2008 3:24 am

    Ops, got my name wrong in the previous comment :)

    Looks like it was prefilled with the previous posted fields.

  7. Stoffe on July 15th, 2008 5:26 am

    Thanks! :)

  8. Myron on July 15th, 2008 11:14 am

    Looks like you have to have the full vim package installed to use it, otherwise the macros directory does not exist. I noticed I had vim-tiny installed by default.

  9. http://chrisdew.finalcog.com/ on July 16th, 2008 3:47 am

    Thanks.

  10. आशीष शुक्ल on July 16th, 2008 8:51 am

    How about vimmanpager ?

  11. http://mytechieself.blogspot.com/ on July 17th, 2008 5:28 am

    hmm, interesting. For those of us who continue to use Vim on Windows (Gvim) and have chosen to install the command-line version during the install process, the following command in the batch file:

    vim -u %VIM%\macros\less.vim %%1

  12. Mark on August 21st, 2008 9:35 am

    Uh, on most distros, there is already a “view” hard link to vim, so “view” does the same as your tip.

  13. Dr Small on September 24th, 2008 1:39 pm

    Thanks for the tip. It wasn’t in the same location on ArchLinux as it was on Ubuntu, but I found it here:

    /usr/share/vim/macros/less.vim

Leave a Comment




    Subscribe to the RSS feed!


    subscribe to the ubuntu tutorials RSS feed

    Ubuntu Tutorials Fundraiser


    Please Donate to
    Server Improvement

    Target amount: USD1,000.00
    Total Donations: USD255.00
    Amount Needed: USD745.00

    Thank you for your support!

    Click to Donate

    Polls



  • Blogroll

  • Ads by Google