KISS

Keep It Simple Stupid

Bash/zsh: pager with syntax highlighting

| comments

This is a quick reminder of a very useful function for bash/zsh that I use every day:

1
2
3
4
5
# syntax highlighting pager
# use instead of less
function = () {
    /usr/share/vim/vim73/macros/less.sh "$*"
}

Add the lines above to your ~/.zshrc/~/.bashrc and you’ll get two features:

  • one-character function name significantly speeds up typing (instead of less), and

  • syntax highlighting powered by vim (you need to have it installed, obviously).

The original idea is posted here: http://machine-cycle.blogspot.com/2007/10/syntax-highlighting-pager.html. It was tested in bash and used - as the name, but my zsh produced the following error: cd:cd:10: string not in pwd: -. Turned out zsh (or https://github.com/robbyrussell/oh-my-zsh/) enabled this feature when - was acting as cd - (that is, jumping to previous directory). Thus, the function name = works better here.

Comments