1 " Vim script to work like "less"
2 " Maintainer: Bram Moolenaar <Bram@vim.org>
3 " Last Change: 2006 Dec 05
5 " Avoid loading this file twice, allow the user to define his own script.
6 if exists("loaded_less")
11 " If not reading from stdin, skip files that can't be read.
12 " Exit if there is no file at all.
16 if filereadable(argv(s:i))
22 if isdirectory(argv(s:i))
23 echomsg "Skipping directory " . argv(s:i)
24 elseif getftime(argv(s:i)) < 0
25 echomsg "Skipping non-existing file " . argv(s:i)
27 echomsg "Skipping unreadable file " . argv(s:i)
44 " Don't remember file names and positions
47 " Inhibit screen updates while searching
51 " Used after each command: put cursor at end and display position
53 noremap <SID>L L0:redraw<CR>:file<CR>
54 au VimEnter * normal! L0
56 noremap <SID>L Lg0:redraw<CR>:file<CR>
57 au VimEnter * normal! Lg0
60 " When reading from stdin don't consider the file modified.
61 au VimEnter * set nomod
63 " Can't modify the text
67 noremap h :call <SID>Help()<CR>
70 echo "<Space> One page forward b One page backward"
71 echo "d Half a page forward u Half a page backward"
72 echo "<Enter> One line forward k One line backward"
73 echo "G End of file g Start of file"
74 echo "N% percentage in file"
76 echo "/pattern Search for pattern ?pattern Search backward for pattern"
77 echo "n next pattern match N Previous pattern match"
79 echo ":n<Enter> Next file :p<Enter> Previous file"
81 echo "q Quit v Edit file"
82 let i = input("Hit Enter to continue")
85 " Scroll one page forward
86 noremap <script> <Space> :call <SID>NextPage()<CR><SID>L
91 map <Esc><Space> <Space>
93 if line(".") == line("$")
94 if argidx() + 1 >= argc()
104 " Re-read file and page forward "tail -f"
105 map F :e<CR>G<SID>L:sleep 1<CR>F
107 " Scroll half a page forward
108 noremap <script> d <C-D><SID>L
111 " Scroll one line forward
112 noremap <script> <CR> <C-E><SID>L
119 " Scroll one page backward
120 noremap <script> b <C-B><SID>L
125 " Scroll half a page backward
126 noremap <script> u <C-U><SID>L
127 noremap <script> <C-U> <C-U><SID>L
129 " Scroll one line backward
130 noremap <script> k <C-Y><SID>L
137 noremap <script> r <C-L><SID>L
138 noremap <script> <C-R> <C-L><SID>L
139 noremap <script> R <C-L><SID>L
142 noremap <script> g gg<SID>L
147 noremap <script> G G<SID>L
152 noremap <script> % %<SID>L
156 noremap <script> / H$:call <SID>Forward()<CR>/
158 noremap <script> ? H0:call <SID>Backward()<CR>?
160 noremap <script> ? Hg0:call <SID>Backward()<CR>?
165 noremap <script> n H$nzt<SID>L
167 noremap <script> N H0Nzt<SID>L
169 noremap <script> N Hg0Nzt<SID>L
171 cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L
177 noremap <script> n H0nzt<SID>L
179 noremap <script> n Hg0nzt<SID>L
181 noremap <script> N H$Nzt<SID>L
182 cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L
190 " Switch to editing (switch off less mode)
191 map v :silent call <SID>End()<CR>