Using vim as a syntax-highlighting pager
From Vim Tips Wiki
created 2001 · complexity intermediate · author Mary Ellen Foster · version 5.7
If you want to use Vim's syntax highlighting in a pager, here's how. Since version 6, Vim comes with a script
$VIMRUNTIME/macros/less.sh, and this gives syntax highlighting in a pager. See :help less.
The original tip (below) was for a "more"-style pager. It is kept here because it explains the principles nicely.
First, create a vimrc like the following – I called mine
" No compatibility – necessary for mappings to work. set nocompatible " Status line set laststatus=0 set cmdheight=1 set nomodifiable " Only in version 6.0 set readonly " My xterms have a navy-blue background, so I need this line too. set background=dark " Turn syntax on syntax enable " No menu bar and tool bar set guioptions=aiMr " Key bindings. nmap b <C-B><C-G> nmap q :q!<CR> nmap <Up> <C-Y> nmap <Down> <C-E> " To type the following line, type *two* C-V's followed by two spaces. This " is how you map the spacebar. nmap ^V <C-F><C-G>
Then, to use this .vimrc, add an alias. If you're using tcsh, the syntax will be something like:
alias vmore "vim -u ~/.vimrc.more -"
Then you can type
program | vmore to view
program's output in this "pager". Spacebar will move down, 'b' will move back up, and 'q' quits. You can add mappings for other keys if you want to, also.
Those who like to use Vim as a viewer might want to see Using Vim as a man-page viewer under Unix.
 Related plugins
- vimpager is an enhanced version of the built-in script.