When I use vim to edit a markdown file I have nice syntax coloring (via vim-markdown and vim-markdown-preview plug-ins).
I would like to have this same syntax coloring when I am using less (pager) to view a file. Is there a way to get less to do this syntax coloring? or is there another pager that has this functionality?
I now use, from best to worse, vimpager
, pigmentize
, highlight
, src-hilite-lesspipe.sh
, less
, and then more
; using bash to determine what is available on whichever system I am on.
Here is what I finally arrived at:
.bash_profile
:
#############################################
# Pager #
#############################################
PAGER='more'
export PAGER
if type less &> /dev/null; then
LESS='-i -R -e -X -z-2 -M -P%t?f%f :stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...'
LESSCHARSET='utf-8'
LESSHISTFILE=-
PAGER='less'
MANPAGER='less'
export LESS LESSCHARSET LESSHISTFILE PAGER MANPAGER
export LESS_TERMCAP_so="$(tput bold; tput setaf 0; tput setab 4)" # begin standout
export LESS_TERMCAP_se="$(tput sgr0)" # end standout
export LESS_TERMCAP_us="$(tput smul; tput setaf 3)" # begin underscore
export LESS_TERMCAP_ue="$(tput rmul; tput sgr0)" # end underscore
export LESS_TERMCAP_mr="$(tput rev)" # begin reverse
export LESS_TERMCAP_mb="$(tput blink)" # begin blink
export LESS_TERMCAP_mh="$(tput dim)" # begin dim
export LESS_TERMCAP_md="$(tput bold; tput setaf 6)" # begin bold
export LESS_TERMCAP_ZH="$(tput sitm)" # begin italics
export LESS_TERMCAP_ZR="$(tput ritm)" # end italics
export LESS_TERMCAP_me="$(tput sgr0)" # end all modes
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
if type src-hilite-lesspipe.sh &> /dev/null; then
export LESSOPEN="| src-hilite-lesspipe.sh %s"
fi
if type highlight &> /dev/null; then
export LESSOPEN="| highlight --out-format=xterm256 --style=solarized-dark %s"
fi
if type pygmentize &> /dev/null; then
export LESSOPEN="| pygmentize -O style=solarized-dark -f terminal256 %s"
fi
fi
if type vimpager &> /dev/null; then
export PAGER='vimpager'
fi
if type vimcat &> /dev/null; then
alias v='vimcat'
fi