Mercurial > vim
annotate runtime/macros/less.vim @ 17893:e4d3b6c466d4 v8.1.1943
patch 8.1.1943: more code can be moved to evalvars.c
Commit: https://github.com/vim/vim/commit/8d71b54409ca6cf989dfb7d7fe265768fb7fe062
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Aug 30 15:46:30 2019 +0200
patch 8.1.1943: more code can be moved to evalvars.c
Problem: More code can be moved to evalvars.c.
Solution: Move it, clean up comments. Also move some window related
functions to window.c. (Yegappan Lakshmanan, closes #4874)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 30 Aug 2019 16:00:04 +0200 |
parents | 4aae8146c21f |
children | 74e3316c1d5a |
rev | line source |
---|---|
7 | 1 " Vim script to work like "less" |
2 " Maintainer: Bram Moolenaar <Bram@vim.org> | |
11347 | 3 " Last Change: 2017 Mar 31 |
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" | |
11347 | 84 if &foldmethod != "manual" |
85 echo "\n" | |
86 echo "zR open all folds zm increase fold level" | |
87 endif | |
7 | 88 echo "\n" |
89 echo ":n<Enter> Next file :p<Enter> Previous file" | |
90 echo "\n" | |
91 echo "q Quit v Edit file" | |
92 let i = input("Hit Enter to continue") | |
93 endfun | |
94 | |
95 " Scroll one page forward | |
96 noremap <script> <Space> :call <SID>NextPage()<CR><SID>L | |
97 map <C-V> <Space> | |
98 map f <Space> | |
99 map <C-F> <Space> | |
5908 | 100 map <PageDown> <Space> |
101 map <kPageDown> <Space> | |
102 map <S-Down> <Space> | |
11347 | 103 " If 'foldmethod' was changed keep the "z" commands, e.g. "zR" to open all |
104 " folds. | |
105 if &foldmethod == "manual" | |
106 map z <Space> | |
107 endif | |
7 | 108 map <Esc><Space> <Space> |
109 fun! s:NextPage() | |
110 if line(".") == line("$") | |
111 if argidx() + 1 >= argc() | |
3513 | 112 " Don't quit at the end of the last file |
113 return | |
7 | 114 endif |
115 next | |
116 1 | |
117 else | |
118 exe "normal! \<C-F>" | |
119 endif | |
120 endfun | |
121 | |
122 " Re-read file and page forward "tail -f" | |
123 map F :e<CR>G<SID>L:sleep 1<CR>F | |
124 | |
125 " Scroll half a page forward | |
126 noremap <script> d <C-D><SID>L | |
127 map <C-D> d | |
128 | |
129 " Scroll one line forward | |
130 noremap <script> <CR> <C-E><SID>L | |
131 map <C-N> <CR> | |
132 map e <CR> | |
133 map <C-E> <CR> | |
134 map j <CR> | |
135 map <C-J> <CR> | |
5908 | 136 map <Down> <CR> |
7 | 137 |
138 " Scroll one page backward | |
139 noremap <script> b <C-B><SID>L | |
140 map <C-B> b | |
5908 | 141 map <PageUp> b |
142 map <kPageUp> b | |
143 map <S-Up> b | |
7 | 144 map w b |
145 map <Esc>v b | |
146 | |
147 " Scroll half a page backward | |
148 noremap <script> u <C-U><SID>L | |
149 noremap <script> <C-U> <C-U><SID>L | |
150 | |
151 " Scroll one line backward | |
152 noremap <script> k <C-Y><SID>L | |
153 map y k | |
154 map <C-Y> k | |
155 map <C-P> k | |
156 map <C-K> k | |
5908 | 157 map <Up> k |
7 | 158 |
159 " Redraw | |
160 noremap <script> r <C-L><SID>L | |
161 noremap <script> <C-R> <C-L><SID>L | |
162 noremap <script> R <C-L><SID>L | |
163 | |
164 " Start of file | |
165 noremap <script> g gg<SID>L | |
166 map < g | |
167 map <Esc>< g | |
5908 | 168 map <Home> g |
169 map <kHome> g | |
7 | 170 |
171 " End of file | |
172 noremap <script> G G<SID>L | |
173 map > G | |
174 map <Esc>> G | |
5908 | 175 map <End> G |
176 map <kEnd> G | |
7 | 177 |
178 " Go to percentage | |
179 noremap <script> % %<SID>L | |
180 map p % | |
181 | |
182 " Search | |
183 noremap <script> / H$:call <SID>Forward()<CR>/ | |
184 if &wrap | |
185 noremap <script> ? H0:call <SID>Backward()<CR>? | |
186 else | |
187 noremap <script> ? Hg0:call <SID>Backward()<CR>? | |
188 endif | |
189 | |
190 fun! s:Forward() | |
191 " Searching forward | |
192 noremap <script> n H$nzt<SID>L | |
193 if &wrap | |
194 noremap <script> N H0Nzt<SID>L | |
195 else | |
196 noremap <script> N Hg0Nzt<SID>L | |
197 endif | |
1125 | 198 cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L |
7 | 199 endfun |
200 | |
201 fun! s:Backward() | |
202 " Searching backward | |
203 if &wrap | |
204 noremap <script> n H0nzt<SID>L | |
205 else | |
206 noremap <script> n Hg0nzt<SID>L | |
207 endif | |
208 noremap <script> N H$Nzt<SID>L | |
1125 | 209 cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L |
7 | 210 endfun |
211 | |
212 call s:Forward() | |
5908 | 213 cunmap <CR> |
7 | 214 |
215 " Quitting | |
216 noremap q :q<CR> | |
217 | |
218 " Switch to editing (switch off less mode) | |
219 map v :silent call <SID>End()<CR> | |
220 fun! s:End() | |
221 set ma | |
874 | 222 if exists('s:lz') |
7 | 223 let &lz = s:lz |
224 endif | |
225 unmap h | |
226 unmap H | |
227 unmap <Space> | |
228 unmap <C-V> | |
229 unmap f | |
230 unmap <C-F> | |
231 unmap z | |
232 unmap <Esc><Space> | |
233 unmap F | |
234 unmap d | |
235 unmap <C-D> | |
236 unmap <CR> | |
237 unmap <C-N> | |
238 unmap e | |
239 unmap <C-E> | |
240 unmap j | |
241 unmap <C-J> | |
242 unmap b | |
243 unmap <C-B> | |
244 unmap w | |
245 unmap <Esc>v | |
246 unmap u | |
247 unmap <C-U> | |
248 unmap k | |
249 unmap y | |
250 unmap <C-Y> | |
251 unmap <C-P> | |
252 unmap <C-K> | |
253 unmap r | |
254 unmap <C-R> | |
255 unmap R | |
256 unmap g | |
257 unmap < | |
258 unmap <Esc>< | |
259 unmap G | |
260 unmap > | |
261 unmap <Esc>> | |
262 unmap % | |
263 unmap p | |
264 unmap n | |
265 unmap N | |
266 unmap q | |
267 unmap v | |
268 unmap / | |
269 unmap ? | |
5908 | 270 unmap <Up> |
271 unmap <Down> | |
272 unmap <PageDown> | |
273 unmap <kPageDown> | |
274 unmap <PageUp> | |
275 unmap <kPageUp> | |
276 unmap <S-Down> | |
277 unmap <S-Up> | |
278 unmap <Home> | |
279 unmap <kHome> | |
280 unmap <End> | |
281 unmap <kEnd> | |
7 | 282 endfun |
283 | |
284 " vim: sw=2 |