1 " Vim script to work like "less"
2 " Maintainer: Bram Moolenaar <Bram@vim.org>
3 " Last Change: 2012 May 18
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()
95 " Don't quit at the end of the last file
105 " Re-read file and page forward "tail -f"
106 map F :e<CR>G<SID>L:sleep 1<CR>F
108 " Scroll half a page forward
109 noremap <script> d <C-D><SID>L
112 " Scroll one line forward
113 noremap <script> <CR> <C-E><SID>L
120 " Scroll one page backward
121 noremap <script> b <C-B><SID>L
126 " Scroll half a page backward
127 noremap <script> u <C-U><SID>L
128 noremap <script> <C-U> <C-U><SID>L
130 " Scroll one line backward
131 noremap <script> k <C-Y><SID>L
138 noremap <script> r <C-L><SID>L
139 noremap <script> <C-R> <C-L><SID>L
140 noremap <script> R <C-L><SID>L
143 noremap <script> g gg<SID>L
148 noremap <script> G G<SID>L
153 noremap <script> % %<SID>L
157 noremap <script> / H$:call <SID>Forward()<CR>/
159 noremap <script> ? H0:call <SID>Backward()<CR>?
161 noremap <script> ? Hg0:call <SID>Backward()<CR>?
166 noremap <script> n H$nzt<SID>L
168 noremap <script> N H0Nzt<SID>L
170 noremap <script> N Hg0Nzt<SID>L
172 cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L
178 noremap <script> n H0nzt<SID>L
180 noremap <script> n Hg0nzt<SID>L
182 noremap <script> N H$Nzt<SID>L
183 cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L
191 " Switch to editing (switch off less mode)
192 map v :silent call <SID>End()<CR>