Mercurial > vim
annotate runtime/macros/less.vim @ 4335:3887b02953ce v7.3.917
updated for version 7.3.917
Problem: When a path ends in a backslash appending a comma has the wrong
effect.
Solution: Replace a trailing backslash with a slash. (Nazri Ramliy)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 24 Apr 2013 17:34:20 +0200 |
parents | dd6c2497c997 |
children | 32de51778c27 |
rev | line source |
---|---|
7 | 1 " Vim script to work like "less" |
2 " Maintainer: Bram Moolenaar <Bram@vim.org> | |
3526
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
3513
diff
changeset
|
3 " Last Change: 2012 May 18 |
7 | 4 |
5 " Avoid loading this file twice, allow the user to define his own script. | |
6 if exists("loaded_less") | |
7 finish | |
8 endif | |
9 let loaded_less = 1 | |
10 | |
11 " If not reading from stdin, skip files that can't be read. | |
12 " Exit if there is no file at all. | |
13 if argc() > 0 | |
14 let s:i = 0 | |
15 while 1 | |
16 if filereadable(argv(s:i)) | |
17 if s:i != 0 | |
18 sleep 3 | |
19 endif | |
20 break | |
21 endif | |
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) | |
26 else | |
27 echomsg "Skipping unreadable file " . argv(s:i) | |
28 endif | |
29 echo "\n" | |
30 let s:i = s:i + 1 | |
31 if s:i == argc() | |
32 quit | |
33 endif | |
34 next | |
35 endwhile | |
36 endif | |
37 | |
38 set nocp | |
39 syntax on | |
40 set so=0 | |
41 set hlsearch | |
42 set incsearch | |
43 nohlsearch | |
44 " Don't remember file names and positions | |
45 set viminfo= | |
46 set nows | |
47 " Inhibit screen updates while searching | |
48 let s:lz = &lz | |
49 set lz | |
50 | |
51 " Used after each command: put cursor at end and display position | |
52 if &wrap | |
53 noremap <SID>L L0:redraw<CR>:file<CR> | |
54 au VimEnter * normal! L0 | |
55 else | |
56 noremap <SID>L Lg0:redraw<CR>:file<CR> | |
57 au VimEnter * normal! Lg0 | |
58 endif | |
59 | |
60 " When reading from stdin don't consider the file modified. | |
61 au VimEnter * set nomod | |
62 | |
63 " Can't modify the text | |
64 set noma | |
65 | |
66 " Give help | |
67 noremap h :call <SID>Help()<CR> | |
68 map H h | |
69 fun! s:Help() | |
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" | |
75 echo "\n" | |
76 echo "/pattern Search for pattern ?pattern Search backward for pattern" | |
77 echo "n next pattern match N Previous pattern match" | |
78 echo "\n" | |
79 echo ":n<Enter> Next file :p<Enter> Previous file" | |
80 echo "\n" | |
81 echo "q Quit v Edit file" | |
82 let i = input("Hit Enter to continue") | |
83 endfun | |
84 | |
85 " Scroll one page forward | |
86 noremap <script> <Space> :call <SID>NextPage()<CR><SID>L | |
87 map <C-V> <Space> | |
88 map f <Space> | |
89 map <C-F> <Space> | |
90 map z <Space> | |
91 map <Esc><Space> <Space> | |
92 fun! s:NextPage() | |
93 if line(".") == line("$") | |
94 if argidx() + 1 >= argc() | |
3513 | 95 " Don't quit at the end of the last file |
96 return | |
7 | 97 endif |
98 next | |
99 1 | |
100 else | |
101 exe "normal! \<C-F>" | |
102 endif | |
103 endfun | |
104 | |
105 " Re-read file and page forward "tail -f" | |
106 map F :e<CR>G<SID>L:sleep 1<CR>F | |
107 | |
108 " Scroll half a page forward | |
109 noremap <script> d <C-D><SID>L | |
110 map <C-D> d | |
111 | |
112 " Scroll one line forward | |
113 noremap <script> <CR> <C-E><SID>L | |
114 map <C-N> <CR> | |
115 map e <CR> | |
116 map <C-E> <CR> | |
117 map j <CR> | |
118 map <C-J> <CR> | |
119 | |
120 " Scroll one page backward | |
121 noremap <script> b <C-B><SID>L | |
122 map <C-B> b | |
123 map w b | |
124 map <Esc>v b | |
125 | |
126 " Scroll half a page backward | |
127 noremap <script> u <C-U><SID>L | |
128 noremap <script> <C-U> <C-U><SID>L | |
129 | |
130 " Scroll one line backward | |
131 noremap <script> k <C-Y><SID>L | |
132 map y k | |
133 map <C-Y> k | |
134 map <C-P> k | |
135 map <C-K> k | |
136 | |
137 " Redraw | |
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 | |
141 | |
142 " Start of file | |
143 noremap <script> g gg<SID>L | |
144 map < g | |
145 map <Esc>< g | |
146 | |
147 " End of file | |
148 noremap <script> G G<SID>L | |
149 map > G | |
150 map <Esc>> G | |
151 | |
152 " Go to percentage | |
153 noremap <script> % %<SID>L | |
154 map p % | |
155 | |
156 " Search | |
157 noremap <script> / H$:call <SID>Forward()<CR>/ | |
158 if &wrap | |
159 noremap <script> ? H0:call <SID>Backward()<CR>? | |
160 else | |
161 noremap <script> ? Hg0:call <SID>Backward()<CR>? | |
162 endif | |
163 | |
164 fun! s:Forward() | |
165 " Searching forward | |
166 noremap <script> n H$nzt<SID>L | |
167 if &wrap | |
168 noremap <script> N H0Nzt<SID>L | |
169 else | |
170 noremap <script> N Hg0Nzt<SID>L | |
171 endif | |
1125 | 172 cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L |
7 | 173 endfun |
174 | |
175 fun! s:Backward() | |
176 " Searching backward | |
177 if &wrap | |
178 noremap <script> n H0nzt<SID>L | |
179 else | |
180 noremap <script> n Hg0nzt<SID>L | |
181 endif | |
182 noremap <script> N H$Nzt<SID>L | |
1125 | 183 cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L |
7 | 184 endfun |
185 | |
186 call s:Forward() | |
187 | |
188 " Quitting | |
189 noremap q :q<CR> | |
190 | |
191 " Switch to editing (switch off less mode) | |
192 map v :silent call <SID>End()<CR> | |
193 fun! s:End() | |
194 set ma | |
874 | 195 if exists('s:lz') |
7 | 196 let &lz = s:lz |
197 endif | |
198 unmap h | |
199 unmap H | |
200 unmap <Space> | |
201 unmap <C-V> | |
202 unmap f | |
203 unmap <C-F> | |
204 unmap z | |
205 unmap <Esc><Space> | |
206 unmap F | |
207 unmap d | |
208 unmap <C-D> | |
209 unmap <CR> | |
210 unmap <C-N> | |
211 unmap e | |
212 unmap <C-E> | |
213 unmap j | |
214 unmap <C-J> | |
215 unmap b | |
216 unmap <C-B> | |
217 unmap w | |
218 unmap <Esc>v | |
219 unmap u | |
220 unmap <C-U> | |
221 unmap k | |
222 unmap y | |
223 unmap <C-Y> | |
224 unmap <C-P> | |
225 unmap <C-K> | |
226 unmap r | |
227 unmap <C-R> | |
228 unmap R | |
229 unmap g | |
230 unmap < | |
231 unmap <Esc>< | |
232 unmap G | |
233 unmap > | |
234 unmap <Esc>> | |
235 unmap % | |
236 unmap p | |
237 unmap n | |
238 unmap N | |
239 unmap q | |
240 unmap v | |
241 unmap / | |
242 unmap ? | |
243 endfun | |
244 | |
245 " vim: sw=2 |