From 6e1754f0c251453af82de6248f6668ebd066f168 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Fri, 30 Jan 2015 12:00:01 +0100 Subject: [PATCH] Add the less.vim macro --- macros/less.vim | 270 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 270 insertions(+) create mode 100644 macros/less.vim diff --git a/macros/less.vim b/macros/less.vim new file mode 100644 index 0000000..9042e84 --- /dev/null +++ b/macros/less.vim @@ -0,0 +1,270 @@ +" Vim script to work like "less" +" Maintainer: Bram Moolenaar +" Last Change: 2014 May 13 + +" 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 + +set nocp +syntax on +set so=0 +set hlsearch +set incsearch +nohlsearch +" Don't remember file names and positions +set viminfo= +set nows +" Inhibit screen updates while searching +let s:lz = &lz +set lz + +" 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 +set noma + +" 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" + 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