Last Updated: February 25, 2016
·
2.359K
· lukaszkorecki

Turn vim into a pager/less/more

Little known fact - Vim ships with a script which when invoked turns it into a 'less-like' pager/file viewer.

Benefits?

Syntax highlighting - useful for viewing not only source files, but also configs and logs.

Keybindings!

Here's a function I got in my zshrc (it should also work in bash)
it detects where less.sh is located and invokes it.

# make vim a pager                                                              
function vless() {                                                        
  local less_path=`find $(vim --version | awk ' /fall-back/ { gsub(/\"/,"",$NF); print $NF }'  )/ -name less.sh`
  if [[ -z $less_path ]]; then                                               
    echo 'less.sh not found'                                                 
    exit 1                                                                   
  fi                                                                         
  $less_path $*                                                              

}                                                                         

Here's a link to my zshrc http://git.io/VU0Q0g