Mercurial > vim
annotate runtime/macros/less.vim @ 8015:b421c7f2f172 v7.4.1302
commit https://github.com/vim/vim/commit/6119e6156e024d9047bbfeb7cdfdae259f9e1b92
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Feb 11 12:48:36 2016 +0100
patch 7.4.1302
Problem: Typo in struct field name. (Ken Takata)
Solution: Rename jf_pi to jv_pi.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 11 Feb 2016 13:00:04 +0100 |
parents | 8896150aba23 |
children | 4aae8146c21f |
rev | line source |
---|---|
7 | 1 " Vim script to work like "less" |
2 " Maintainer: Bram Moolenaar <Bram@vim.org> | |
7245
8896150aba23
commit https://github.com/vim/vim/commit/e392eb41f8dfc01bd13634e534ac6b4d505326f4
Christian Brabandt <cb@256bit.org>
parents:
5908
diff
changeset
|
3 " Last Change: 2015 Nov 15 |
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 | |
7245
8896150aba23
commit https://github.com/vim/vim/commit/e392eb41f8dfc01bd13634e534ac6b4d505326f4
Christian Brabandt <cb@256bit.org>
parents:
5908
diff
changeset
|
51 " Allow the user to define a function, which can set options specifically for |
8896150aba23
commit https://github.com/vim/vim/commit/e392eb41f8dfc01bd13634e534ac6b4d505326f4
Christian Brabandt <cb@256bit.org>
parents:
5908
diff
changeset
|
52 " this script. |
8896150aba23
commit https://github.com/vim/vim/commit/e392eb41f8dfc01bd13634e534ac6b4d505326f4
Christian Brabandt <cb@256bit.org>
parents:
5908
diff
changeset
|
53 if exists('*LessInitFunc') |
8896150aba23
commit https://github.com/vim/vim/commit/e392eb41f8dfc01bd13634e534ac6b4d505326f4
Christian Brabandt <cb@256bit.org>
parents:
5908
diff
changeset
|
54 call LessInitFunc() |
8896150aba23
commit https://github.com/vim/vim/commit/e392eb41f8dfc01bd13634e534ac6b4d505326f4
Christian Brabandt <cb@256bit.org>
parents:
5908
diff
changeset
|
55 endif |
8896150aba23
commit https://github.com/vim/vim/commit/e392eb41f8dfc01bd13634e534ac6b4d505326f4
Christian Brabandt <cb@256bit.org>
parents:
5908
diff
changeset
|
56 |
7 | 57 " Used after each command: put cursor at end and display position |
58 if &wrap | |
59 noremap <SID>L L0:redraw<CR>:file<CR> | |
60 au VimEnter * normal! L0 | |
61 else | |
62 noremap <SID>L Lg0:redraw<CR>:file<CR> | |
63 au VimEnter * normal! Lg0 | |
64 endif | |
65 | |
66 " When reading from stdin don't consider the file modified. | |
67 au VimEnter * set nomod | |
68 | |
69 " Can't modify the text | |
70 set noma | |
71 | |
72 " Give help | |
73 noremap h :call <SID>Help()<CR> | |
74 map H h | |
75 fun! s:Help() | |
76 echo "<Space> One page forward b One page backward" | |
77 echo "d Half a page forward u Half a page backward" | |
78 echo "<Enter> One line forward k One line backward" | |
79 echo "G End of file g Start of file" | |
80 echo "N% percentage in file" | |
81 echo "\n" | |
82 echo "/pattern Search for pattern ?pattern Search backward for pattern" | |
83 echo "n next pattern match N Previous pattern match" | |
84 echo "\n" | |
85 echo ":n<Enter> Next file :p<Enter> Previous file" | |
86 echo "\n" | |
87 echo "q Quit v Edit file" | |
88 let i = input("Hit Enter to continue") | |
89 endfun | |
90 | |
91 " Scroll one page forward | |
92 noremap <script> <Space> :call <SID>NextPage()<CR><SID>L | |
93 map <C-V> <Space> | |
94 map f <Space> | |
95 map <C-F> <Space> | |
5908 | 96 map <PageDown> <Space> |
97 map <kPageDown> <Space> | |
98 map <S-Down> <Space> | |
7 | 99 map z <Space> |
100 map <Esc><Space> <Space> | |
101 fun! s:NextPage() | |
102 if line(".") == line("$") | |
103 if argidx() + 1 >= argc() | |
3513 | 104 " Don't quit at the end of the last file |
105 return | |
7 | 106 endif |
107 next | |
108 1 | |
109 else | |
110 exe "normal! \<C-F>" | |
111 endif | |
112 endfun | |
113 | |
114 " Re-read file and page forward "tail -f" | |
115 map F :e<CR>G<SID>L:sleep 1<CR>F | |
116 | |
117 " Scroll half a page forward | |
118 noremap <script> d <C-D><SID>L | |
119 map <C-D> d | |
120 | |
121 " Scroll one line forward | |
122 noremap <script> <CR> <C-E><SID>L | |
123 map <C-N> <CR> | |
124 map e <CR> | |
125 map <C-E> <CR> | |
126 map j <CR> | |
127 map <C-J> <CR> | |
5908 | 128 map <Down> <CR> |
7 | 129 |
130 " Scroll one page backward | |
131 noremap <script> b <C-B><SID>L | |
132 map <C-B> b | |
5908 | 133 map <PageUp> b |
134 map <kPageUp> b | |
135 map <S-Up> b | |
7 | 136 map w b |
137 map <Esc>v b | |
138 | |
139 " Scroll half a page backward | |
140 noremap <script> u <C-U><SID>L | |
141 noremap <script> <C-U> <C-U><SID>L | |
142 | |
143 " Scroll one line backward | |
144 noremap <script> k <C-Y><SID>L | |
145 map y k | |
146 map <C-Y> k | |
147 map <C-P> k | |
148 map <C-K> k | |
5908 | 149 map <Up> k |
7 | 150 |
151 " Redraw | |
152 noremap <script> r <C-L><SID>L | |
153 noremap <script> <C-R> <C-L><SID>L | |
154 noremap <script> R <C-L><SID>L | |
155 | |
156 " Start of file | |
157 noremap <script> g gg<SID>L | |
158 map < g | |
159 map <Esc>< g | |
5908 | 160 map <Home> g |
161 map <kHome> g | |
7 | 162 |
163 " End of file | |
164 noremap <script> G G<SID>L | |
165 map > G | |
166 map <Esc>> G | |
5908 | 167 map <End> G |
168 map <kEnd> G | |
7 | 169 |
170 " Go to percentage | |
171 noremap <script> % %<SID>L | |
172 map p % | |
173 | |
174 " Search | |
175 noremap <script> / H$:call <SID>Forward()<CR>/ | |
176 if &wrap | |
177 noremap <script> ? H0:call <SID>Backward()<CR>? | |
178 else | |
179 noremap <script> ? Hg0:call <SID>Backward()<CR>? | |
180 endif | |
181 | |
182 fun! s:Forward() | |
183 " Searching forward | |
184 noremap <script> n H$nzt<SID>L | |
185 if &wrap | |
186 noremap <script> N H0Nzt<SID>L | |
187 else | |
188 noremap <script> N Hg0Nzt<SID>L | |
189 endif | |
1125 | 190 cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L |
7 | 191 endfun |
192 | |
193 fun! s:Backward() | |
194 " Searching backward | |
195 if &wrap | |
196 noremap <script> n H0nzt<SID>L | |
197 else | |
198 noremap <script> n Hg0nzt<SID>L | |
199 endif | |
200 noremap <script> N H$Nzt<SID>L | |
1125 | 201 cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L |
7 | 202 endfun |
203 | |
204 call s:Forward() | |
5908 | 205 cunmap <CR> |
7 | 206 |
207 " Quitting | |
208 noremap q :q<CR> | |
209 | |
210 " Switch to editing (switch off less mode) | |
211 map v :silent call <SID>End()<CR> | |
212 fun! s:End() | |
213 set ma | |
874 | 214 if exists('s:lz') |
7 | 215 let &lz = s:lz |
216 endif | |
217 unmap h | |
218 unmap H | |
219 unmap <Space> | |
220 unmap <C-V> | |
221 unmap f | |
222 unmap <C-F> | |
223 unmap z | |
224 unmap <Esc><Space> | |
225 unmap F | |
226 unmap d | |
227 unmap <C-D> | |
228 unmap <CR> | |
229 unmap <C-N> | |
230 unmap e | |
231 unmap <C-E> | |
232 unmap j | |
233 unmap <C-J> | |
234 unmap b | |
235 unmap <C-B> | |
236 unmap w | |
237 unmap <Esc>v | |
238 unmap u | |
239 unmap <C-U> | |
240 unmap k | |
241 unmap y | |
242 unmap <C-Y> | |
243 unmap <C-P> | |
244 unmap <C-K> | |
245 unmap r | |
246 unmap <C-R> | |
247 unmap R | |
248 unmap g | |
249 unmap < | |
250 unmap <Esc>< | |
251 unmap G | |
252 unmap > | |
253 unmap <Esc>> | |
254 unmap % | |
255 unmap p | |
256 unmap n | |
257 unmap N | |
258 unmap q | |
259 unmap v | |
260 unmap / | |
261 unmap ? | |
5908 | 262 unmap <Up> |
263 unmap <Down> | |
264 unmap <PageDown> | |
265 unmap <kPageDown> | |
266 unmap <PageUp> | |
267 unmap <kPageUp> | |
268 unmap <S-Down> | |
269 unmap <S-Up> | |
270 unmap <Home> | |
271 unmap <kHome> | |
272 unmap <End> | |
273 unmap <kEnd> | |
7 | 274 endfun |
275 | |
276 " vim: sw=2 |