" Vim script to work like "less" " Maintainer: Bram Moolenaar " Last Change: 2020 Dec 17 " Avoid loading this file twice, allow the user to define his own script. if exists("loaded_less") finish endif let loaded_less = 1 " If not reading from stdin, skip files that can't be read. " Exit if there is no file at all. if argc() > 0 let s:i = 0 while 1 if filereadable(argv(s:i)) if s:i != 0 sleep 3 endif break endif if isdirectory(argv(s:i)) echomsg "Skipping directory " . argv(s:i) elseif getftime(argv(s:i)) < 0 echomsg "Skipping non-existing file " . argv(s:i) else echomsg "Skipping unreadable file " . argv(s:i) endif echo "\n" let s:i = s:i + 1 if s:i == argc() quit endif next endwhile endif " we don't want 'compatible' here if &cp set nocp endif " enable syntax highlighting if not done already if !get(g:, 'syntax_on', 0) syntax enable endif set so=0 set hlsearch set incsearch nohlsearch " Don't remember file names and positions set shada= set nows " Inhibit screen updates while searching let s:lz = &lz set lz " Allow the user to define a function, which can set options specifically for " this script. if exists('*LessInitFunc') call LessInitFunc() endif " Used after each command: put cursor at end and display position if &wrap noremap L L0:redraw:file au VimEnter * normal! L0 else noremap L Lg0:redraw:file au VimEnter * normal! Lg0 endif " When reading from stdin don't consider the file modified. au VimEnter * set nomod " Can't modify the text or write the file. set nomodifiable readonly " Give help noremap h :call Help() map H h fun! s:Help() echo " One page forward b One page backward" echo "d Half a page forward u Half a page backward" echo " One line forward k One line backward" echo "G End of file g Start of file" echo "N% percentage in file" echo "\n" echo "/pattern Search for pattern ?pattern Search backward for pattern" echo "n next pattern match N Previous pattern match" if &foldmethod != "manual" echo "\n" echo "zR open all folds zm increase fold level" endif echo "\n" echo ":n Next file :p Previous file" echo "\n" echo "q Quit v Edit file" let i = input("Hit Enter to continue") endfun " Scroll one page forward noremap