robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonfix(runtime): clean up one-off scripts82b02ae2f2

master
7.8 KiB407 linesraw
1" Vim script to work like "less"
2" Maintainer:	The Vim Project <https://github.com/vim/vim>
3" Last Change:	2024 Feb 15
4" Former Maintainer:	Bram Moolenaar <Bram@vim.org>
5
6" Avoid loading this file twice, allow the user to define his own script.
7if exists("loaded_less")
8  finish
9endif
10let loaded_less = 1
11
12" If not reading from stdin, skip files that can't be read.
13" Exit if there is no file at all.
14if argc() > 0
15  let s:i = 0
16  while 1
17    if filereadable(argv(s:i))
18      if s:i != 0
19	sleep 3
20      endif
21      break
22    endif
23    if isdirectory(argv(s:i))
24      echomsg "Skipping directory " . argv(s:i)
25    elseif getftime(argv(s:i)) < 0
26      echomsg "Skipping non-existing file " . argv(s:i)
27    else
28      echomsg "Skipping unreadable file " . argv(s:i)
29    endif
30    echo "\n"
31    let s:i = s:i + 1
32    if s:i == argc()
33      quit
34    endif
35    next
36  endwhile
37endif
38
39" we don't want 'compatible' here
40if &cp
41  set nocp
42endif
43
44" enable syntax highlighting if not done already
45if !get(g:, 'syntax_on', 0)
46  syntax enable
47endif
48
49set so=0
50set hlsearch
51set incsearch
52nohlsearch
53" Don't remember file names and positions
54set shada=
55set nows
56" Inhibit screen updates while searching
57let s:lz = &lz
58set lz
59
60" Allow the user to define a function, which can set options specifically for
61" this script.
62if exists('*LessInitFunc')
63  call LessInitFunc()
64endif
65
66" Used after each command: put cursor at end and display position
67if &wrap
68  noremap <SID>L L0:redraw<CR>:file<CR>
69  au VimEnter * normal! L0
70else
71  noremap <SID>L Lg0:redraw<CR>:file<CR>
72  au VimEnter * normal! Lg0
73endif
74
75" When reading from stdin don't consider the file modified.
76au VimEnter * set nomod
77
78" Can't modify the text or write the file.
79set nomodifiable readonly
80
81" Give help
82noremap h :call <SID>Help()<CR>
83map H h
84fun! s:Help()
85  echo "<Space>   One page forward          b         One page backward"
86  echo "d         Half a page forward       u         Half a page backward"
87  echo "<Enter>   One line forward          k         One line backward"
88  echo "G         End of file               g         Start of file"
89  echo "N%        percentage in file"
90  echo "\n"
91  echo "/pattern  Search for pattern        ?pattern  Search backward for pattern"
92  echo "n         next pattern match        N         Previous pattern match"
93  if &foldmethod != "manual"
94  echo "\n"
95    echo "zR        open all folds            zm        increase fold level"
96  endif
97  echo "\n"
98  echo ":n<Enter> Next file                 :p<Enter> Previous file"
99  echo "\n"
100  echo "q         Quit                      v         Edit file"
101  let i = input("Hit Enter to continue")
102endfun
103
104" Scroll one page forward
105noremap <script> <Space> :call <SID>NextPage()<CR><SID>L
106map <C-V> <Space>
107map f <Space>
108map <C-F> <Space>
109map <PageDown> <Space>
110map <kPageDown> <Space>
111map <S-Down> <Space>
112" If 'foldmethod' was changed keep the "z" commands, e.g. "zR" to open all
113" folds.
114if &foldmethod == "manual"
115  map z <Space>
116endif
117map <Esc><Space> <Space>
118fun! s:NextPage()
119  if line(".") == line("$")
120    if argidx() + 1 >= argc()
121      " Don't quit at the end of the last file
122      return
123    endif
124    next
125    1
126  else
127    exe "normal! \<C-F>"
128  endif
129endfun
130
131" Re-read file and page forward "tail -f"
132map F :e<CR>G<SID>L:sleep 1<CR>F
133
134" Scroll half a page forward
135noremap <script> d <C-D><SID>L
136map <C-D> d
137
138" Scroll one line forward
139noremap <script> <CR> <C-E><SID>L
140map <C-N> <CR>
141map e <CR>
142map <C-E> <CR>
143map j <CR>
144map <C-J> <CR>
145map <Down> <CR>
146
147" Scroll one page backward
148noremap <script> b <C-B><SID>L
149map <C-B> b
150map <PageUp> b
151map <kPageUp> b
152map <S-Up> b
153map w b
154map <Esc>v b
155
156" Scroll half a page backward
157noremap <script> u <C-U><SID>L
158noremap <script> <C-U> <C-U><SID>L
159
160" Scroll one line backward
161noremap <script> k <C-Y><SID>L
162map y k
163map <C-Y> k
164map <C-P> k
165map <C-K> k
166map <Up> k
167
168" Redraw
169noremap <script> r <C-L><SID>L
170noremap <script> <C-R> <C-L><SID>L
171noremap <script> R <C-L><SID>L
172
173" Start of file
174noremap <script> g gg<SID>L
175map < g
176map <Esc>< g
177map <Home> g
178map <kHome> g
179
180" End of file
181noremap <script> G G<SID>L
182map > G
183map <Esc>> G
184map <End> G
185map <kEnd> G
186
187" Go to percentage
188noremap <script> % %<SID>L
189map p %
190
191" Search
192noremap <script> / H$:call <SID>Forward()<CR>/
193if &wrap
194  noremap <script> ? H0:call <SID>Backward()<CR>?
195else
196  noremap <script> ? Hg0:call <SID>Backward()<CR>?
197endif
198
199fun! s:Forward()
200  " Searching forward
201  noremap <script> n H$nzt<SID>L
202  if &wrap
203    noremap <script> N H0Nzt<SID>L
204  else
205    noremap <script> N Hg0Nzt<SID>L
206  endif
207  cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L
208endfun
209
210fun! s:Backward()
211  " Searching backward
212  if &wrap
213    noremap <script> n H0nzt<SID>L
214  else
215    noremap <script> n Hg0nzt<SID>L
216  endif
217  noremap <script> N H$Nzt<SID>L
218  cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L
219endfun
220
221call s:Forward()
222cunmap <CR>
223
224" Quitting
225noremap q :q<CR>
226
227" Switch to editing (switch off less mode)
228map v :silent call <SID>End()<CR>
229fun! s:End()
230  set modifiable noreadonly
231  if exists('s:lz')
232    let &lz = s:lz
233  endif
234  if !empty(maparg('h'))
235    unmap h
236  endif
237  if !empty(maparg('H'))
238    unmap H
239  endif
240  if !empty(maparg('<Space>'))
241    unmap <Space>
242  endif
243  if !empty(maparg('<C-V>'))
244    unmap <C-V>
245  endif
246  if !empty(maparg('f'))
247    unmap f
248  endif
249  if !empty(maparg('<C-F>'))
250    unmap <C-F>
251  endif
252  if !empty(maparg('z'))
253    unmap z
254  endif
255  if !empty(maparg('<Esc><Space>'))
256    unmap <Esc><Space>
257  endif
258  if !empty(maparg('F'))
259    unmap F
260  endif
261  if !empty(maparg('d'))
262    unmap d
263  endif
264  if !empty(maparg('<C-D>'))
265    unmap <C-D>
266  endif
267  if !empty(maparg('<CR>'))
268    unmap <CR>
269  endif
270  if !empty(maparg('<C-N>'))
271    unmap <C-N>
272  endif
273  if !empty(maparg('e'))
274    unmap e
275  endif
276  if !empty(maparg('<C-E>'))
277    unmap <C-E>
278  endif
279  if !empty(maparg('j'))
280    unmap j
281  endif
282  if !empty(maparg('<C-J>'))
283    unmap <C-J>
284  endif
285  if !empty(maparg('b'))
286    unmap b
287  endif
288  if !empty(maparg('<C-B>'))
289    unmap <C-B>
290  endif
291  if !empty(maparg('w'))
292    unmap w
293  endif
294  if !empty(maparg('<Esc>v'))
295    unmap <Esc>v
296  endif
297  if !empty(maparg('u'))
298    unmap u
299  endif
300  if !empty(maparg('<C-U>'))
301    unmap <C-U>
302  endif
303  if !empty(maparg('k'))
304    unmap k
305  endif
306  if !empty(maparg('y'))
307    unmap y
308  endif
309  if !empty(maparg('<C-Y>'))
310    unmap <C-Y>
311  endif
312  if !empty(maparg('<C-P>'))
313    unmap <C-P>
314  endif
315  if !empty(maparg('<C-K>'))
316    unmap <C-K>
317  endif
318  if !empty(maparg('r'))
319    unmap r
320  endif
321  if !empty(maparg('<C-R>'))
322    unmap <C-R>
323  endif
324  if !empty(maparg('R'))
325    unmap R
326  endif
327  if !empty(maparg('g'))
328    unmap g
329  endif
330  if !empty(maparg('<'))
331    unmap <
332  endif
333  if !empty(maparg('<Esc><'))
334    unmap <Esc><
335  endif
336  if !empty(maparg('G'))
337    unmap G
338  endif
339  if !empty(maparg('>'))
340    unmap >
341  endif
342  if !empty(maparg('<Esc>>'))
343    unmap <Esc>>
344  endif
345  if !empty(maparg('%'))
346    unmap %
347  endif
348  if !empty(maparg('p'))
349    unmap p
350  endif
351  if !empty(maparg('n'))
352    unmap n
353  endif
354  if !empty(maparg('N'))
355    unmap N
356  endif
357  if !empty(maparg('q'))
358    unmap q
359  endif
360  if !empty(maparg('v'))
361    unmap v
362  endif
363  if !empty(maparg('/'))
364    unmap /
365  endif
366  if !empty(maparg('?'))
367    unmap ?
368  endif
369  if !empty(maparg('<Up>'))
370    unmap <Up>
371  endif
372  if !empty(maparg('<Down>'))
373    unmap <Down>
374  endif
375  if !empty(maparg('<PageDown>'))
376    unmap <PageDown>
377  endif
378  if !empty(maparg('<kPageDown>'))
379    unmap <kPageDown>
380  endif
381  if !empty(maparg('<PageUp>'))
382    unmap <PageUp>
383  endif
384  if !empty(maparg('<kPageUp>'))
385    unmap <kPageUp>
386  endif
387  if !empty(maparg('<S-Down>'))
388    unmap <S-Down>
389  endif
390  if !empty(maparg('<S-Up>'))
391    unmap <S-Up>
392  endif
393  if !empty(maparg('<Home>'))
394    unmap <Home>
395  endif
396  if !empty(maparg('<kHome>'))
397    unmap <kHome>
398  endif
399  if !empty(maparg('<End>'))
400    unmap <End>
401  endif
402  if !empty(maparg('<kEnd>'))
403    unmap <kEnd>
404  endif
405endfun
406
407" vim: sw=2