robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
82b02ae2f2
master
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" ) 8finish 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 15let s: i = 0 16while 1 17if filereadable ( argv ( s: i )) 18if s: i != 0 19sleep 3 20endif 21break 22endif 23if isdirectory ( argv ( s: i )) 24echomsg "Skipping directory " . argv ( s: i ) 25elseif getftime ( argv ( s: i )) < 0 26echomsg "Skipping non-existing file " . argv ( s: i ) 27else 28echomsg "Skipping unreadable file " . argv ( s: i ) 29endif 30echo "\n" 31let s: i = s: i + 1 32if s: i == argc () 33quit 34endif 35next 36endwhile 37endif 38 39" we don't want 'compatible' here 40if & cp 41set nocp 42endif 43 44" enable syntax highlighting if not done already 45if ! get ( g:, 'syntax_on' , 0 ) 46syntax 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' ) 63call LessInitFunc () 64endif 65 66" Used after each command: put cursor at end and display position 67if & wrap 68noremap < SID > L L0:redraw< CR > :file< CR > 69au VimEnter * normal ! L0 70else 71noremap < SID > L Lg0:redraw< CR > :file< CR > 72au 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 () 85echo "<Space> One page forward b One page backward" 86echo "d Half a page forward u Half a page backward" 87echo "<Enter> One line forward k One line backward" 88echo "G End of file g Start of file" 89echo "N% percentage in file" 90echo "\n" 91echo "/pattern Search for pattern ?pattern Search backward for pattern" 92echo "n next pattern match N Previous pattern match" 93if & foldmethod != "manual" 94echo "\n" 95echo "zR open all folds zm increase fold level" 96endif 97echo "\n" 98echo ":n<Enter> Next file :p<Enter> Previous file" 99echo "\n" 100echo "q Quit v Edit file" 101let 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" 115map z< Space > 116endif 117map < Esc > <Space > < Space > 118fun ! s: NextPage () 119if line ( "." ) == line ( "$" ) 120if argidx () + 1 >= argc () 121" Don't quit at the end of the last file 122return 123endif 124next 1251 126else 127exe "normal! \<C-F>" 128endif 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 194noremap <script> ? H0:call< SID > Backward()< CR > ? 195else 196noremap <script> ? Hg0:call< SID > Backward()< CR > ? 197endif 198 199fun ! s: Forward () 200" Searching forward 201noremap <script> n H$nzt< SID > L 202if & wrap 203noremap <script> N H0Nzt< SID > L 204else 205noremap <script> N Hg0Nzt< SID > L 206endif 207cnoremap <silent> <script> < CR > < CR > :cunmap< lt > CR>< CR > zt< SID > L 208endfun 209 210fun ! s: Backward () 211" Searching backward 212if & wrap 213noremap <script> n H0nzt< SID > L 214else 215noremap <script> n Hg0nzt< SID > L 216endif 217noremap <script> N H$Nzt< SID > L 218cnoremap <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 () 230set modifiable noreadonly 231if exists ( 's:lz' ) 232let & lz = s: lz 233endif 234if ! empty ( maparg ( 'h' )) 235unmap h 236endif 237if ! empty ( maparg ( 'H' )) 238unmap H 239endif 240if ! empty ( maparg ( '<Space>' )) 241unmap <Space> 242endif 243if ! empty ( maparg ( '<C-V>' )) 244unmap <C-V> 245endif 246if ! empty ( maparg ( 'f' )) 247unmap f 248endif 249if ! empty ( maparg ( '<C-F>' )) 250unmap <C-F> 251endif 252if ! empty ( maparg ( 'z' )) 253unmap z 254endif 255if ! empty ( maparg ( '<Esc><Space>' )) 256unmap <Esc><Space> 257endif 258if ! empty ( maparg ( 'F' )) 259unmap F 260endif 261if ! empty ( maparg ( 'd' )) 262unmap d 263endif 264if ! empty ( maparg ( '<C-D>' )) 265unmap <C-D> 266endif 267if ! empty ( maparg ( '<CR>' )) 268unmap <CR> 269endif 270if ! empty ( maparg ( '<C-N>' )) 271unmap <C-N> 272endif 273if ! empty ( maparg ( 'e' )) 274unmap e 275endif 276if ! empty ( maparg ( '<C-E>' )) 277unmap <C-E> 278endif 279if ! empty ( maparg ( 'j' )) 280unmap j 281endif 282if ! empty ( maparg ( '<C-J>' )) 283unmap <C-J> 284endif 285if ! empty ( maparg ( 'b' )) 286unmap b 287endif 288if ! empty ( maparg ( '<C-B>' )) 289unmap <C-B> 290endif 291if ! empty ( maparg ( 'w' )) 292unmap w 293endif 294if ! empty ( maparg ( '<Esc>v' )) 295unmap <Esc>v 296endif 297if ! empty ( maparg ( 'u' )) 298unmap u 299endif 300if ! empty ( maparg ( '<C-U>' )) 301unmap <C-U> 302endif 303if ! empty ( maparg ( 'k' )) 304unmap k 305endif 306if ! empty ( maparg ( 'y' )) 307unmap y 308endif 309if ! empty ( maparg ( '<C-Y>' )) 310unmap <C-Y> 311endif 312if ! empty ( maparg ( '<C-P>' )) 313unmap <C-P> 314endif 315if ! empty ( maparg ( '<C-K>' )) 316unmap <C-K> 317endif 318if ! empty ( maparg ( 'r' )) 319unmap r 320endif 321if ! empty ( maparg ( '<C-R>' )) 322unmap <C-R> 323endif 324if ! empty ( maparg ( 'R' )) 325unmap R 326endif 327if ! empty ( maparg ( 'g' )) 328unmap g 329endif 330if ! empty ( maparg ( '<' )) 331unmap < 332endif 333if ! empty ( maparg ( '<Esc><' )) 334unmap <Esc>< 335endif 336if ! empty ( maparg ( 'G' )) 337unmap G 338endif 339if ! empty ( maparg ( '>' )) 340unmap > 341endif 342if ! empty ( maparg ( '<Esc>>' )) 343unmap <Esc>> 344endif 345if ! empty ( maparg ( '%' )) 346unmap % 347endif 348if ! empty ( maparg ( 'p' )) 349unmap p 350endif 351if ! empty ( maparg ( 'n' )) 352unmap n 353endif 354if ! empty ( maparg ( 'N' )) 355unmap N 356endif 357if ! empty ( maparg ( 'q' )) 358unmap q 359endif 360if ! empty ( maparg ( 'v' )) 361unmap v 362endif 363if ! empty ( maparg ( '/' )) 364unmap / 365endif 366if ! empty ( maparg ( '?' )) 367unmap ? 368endif 369if ! empty ( maparg ( '<Up>' )) 370unmap <Up> 371endif 372if ! empty ( maparg ( '<Down>' )) 373unmap <Down> 374endif 375if ! empty ( maparg ( '<PageDown>' )) 376unmap <PageDown> 377endif 378if ! empty ( maparg ( '<kPageDown>' )) 379unmap <kPageDown> 380endif 381if ! empty ( maparg ( '<PageUp>' )) 382unmap <PageUp> 383endif 384if ! empty ( maparg ( '<kPageUp>' )) 385unmap <kPageUp> 386endif 387if ! empty ( maparg ( '<S-Down>' )) 388unmap <S-Down> 389endif 390if ! empty ( maparg ( '<S-Up>' )) 391unmap <S-Up> 392endif 393if ! empty ( maparg ( '<Home>' )) 394unmap <Home> 395endif 396if ! empty ( maparg ( '<kHome>' )) 397unmap <kHome> 398endif 399if ! empty ( maparg ( '<End>' )) 400unmap <End> 401endif 402if ! empty ( maparg ( '<kEnd>' )) 403unmap <kEnd> 404endif 405endfun 406 407" vim: sw=2