Syntax Highlighting With Less

I love the syntax highlighting that VI/VIM provides.  I refuse to use any text editor without it.  It just makes it much easier on my eyes to navigate the code.  It’s a very useful feature, and I have no idea why common pagers such as more or less don’t offer this.

Hope is not lost though!  You can use one of VIM’s macros to act similar to less but with highlighting!  This is done by setting an alias in your .bash_profile or .bashrc file, which is in your home directory.  Here’s how:
  1. Open up a terminal and type cd.  This will take you to your home directory in case you aren’t already.
  2. You need to edit your .bashrc or .bash_profile include this alias:  alias vless=’vim -u /usr/share/vim/vim71/macros/less.vim’.  You will most likely have to modify that path depending on your system, but it should always start with /usr/share/vim.
  3. Save and close, then type “. .bashrc” or “. .bash_profile” to re-read the file and have the alias take effect.
You’re done!  Now instead of using less to read a file, you can use vless.  The great thing about aliases is they can be whatever you want.  You can even set it to override less itself if you want.
I’m not sure if basic functionality is any different between less and vless.  Both use / to search and q to quit, and navigate the file the same.  If there are any differences, they certainly don’t bother me.  :)