Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
less.vim408 linesDownload Raw Back to macros
1" Vim script to work like "less"2" Maintainer:	The Vim Project <https://github.com/vim/vim>3" Last Change:	2024 Feb 154" 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  finish9endif10let loaded_less = 111 12" If not reading from stdin, skip files that can't be read.13" Exit if there is no file at all.14if argc() > 015  let s:i = 016  while 117    if filereadable(argv(s:i))18      if s:i != 019	sleep 320      endif21      break22    endif23    if isdirectory(argv(s:i))24      echomsg "Skipping directory " . argv(s:i)25    elseif getftime(argv(s:i)) < 026      echomsg "Skipping non-existing file " . argv(s:i)27    else28      echomsg "Skipping unreadable file " . argv(s:i)29    endif30    echo "\n"31    let s:i = s:i + 132    if s:i == argc()33      quit34    endif35    next36  endwhile37endif38 39" we don't want 'compatible' here40if &cp41  set nocp42endif43 44" enable syntax highlighting if not done already45if !get(g:, 'syntax_on', 0)46  syntax enable47endif48 49set so=050set hlsearch51set incsearch52nohlsearch53" Don't remember file names and positions54set viminfo=55set nows56" Inhibit screen updates while searching57let s:lz = &lz58set lz59 60" Allow the user to define a function, which can set options specifically for61" this script.62if exists('*LessInitFunc')63  call LessInitFunc()64endif65 66" Used after each command: put cursor at end and display position67if &wrap68  noremap <SID>L L0:redraw<CR>:file<CR>69  au VimEnter * normal! L070else71  noremap <SID>L Lg0:redraw<CR>:file<CR>72  au VimEnter * normal! Lg073endif74 75" When reading from stdin don't consider the file modified.76au VimEnter * set nomod77 78" Can't modify the text or write the file.79set nomodifiable readonly80 81" Give help82noremap h :call <SID>Help()<CR>83map H h84fun! 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  endif97  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")102endfun103 104" Scroll one page forward105noremap <script> <Space> :call <SID>NextPage()<CR><SID>L106map <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 all113" folds.114if &foldmethod == "manual"115  map z <Space>116endif117map <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 file122      return123    endif124    next125    1126  else127    exe "normal! \<C-F>"128  endif129endfun130 131" Re-read file and page forward "tail -f"132map F :e<CR>G<SID>L:sleep 1<CR>F133 134" Scroll half a page forward135noremap <script> d <C-D><SID>L136map <C-D> d137 138" Scroll one line forward139noremap <script> <CR> <C-E><SID>L140map <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 backward148noremap <script> b <C-B><SID>L149map <C-B> b150map <PageUp> b151map <kPageUp> b152map <S-Up> b153map w b154map <Esc>v b155 156" Scroll half a page backward157noremap <script> u <C-U><SID>L158noremap <script> <C-U> <C-U><SID>L159 160" Scroll one line backward161noremap <script> k <C-Y><SID>L162map y k163map <C-Y> k164map <C-P> k165map <C-K> k166map <Up> k167 168" Redraw169noremap <script> r <C-L><SID>L170noremap <script> <C-R> <C-L><SID>L171noremap <script> R <C-L><SID>L172 173" Start of file174noremap <script> g gg<SID>L175map < g176map <Esc>< g177map <Home> g178map <kHome> g179 180" End of file181noremap <script> G G<SID>L182map > G183map <Esc>> G184map <End> G185map <kEnd> G186 187" Go to percentage188noremap <script> % %<SID>L189map p %190 191" Search192noremap <script> / H$:call <SID>Forward()<CR>/193if &wrap194  noremap <script> ? H0:call <SID>Backward()<CR>?195else196  noremap <script> ? Hg0:call <SID>Backward()<CR>?197endif198 199fun! s:Forward()200  " Searching forward201  noremap <script> n H$nzt<SID>L202  if &wrap203    noremap <script> N H0Nzt<SID>L204  else205    noremap <script> N Hg0Nzt<SID>L206  endif207  cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L208endfun209 210fun! s:Backward()211  " Searching backward212  if &wrap213    noremap <script> n H0nzt<SID>L214  else215    noremap <script> n Hg0nzt<SID>L216  endif217  noremap <script> N H$Nzt<SID>L218  cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L219endfun220 221call s:Forward()222cunmap <CR>223 224" Quitting225noremap 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 noreadonly231  if exists('s:lz')232    let &lz = s:lz233  endif234  if !empty(maparg('h'))235    unmap h236  endif237  if !empty(maparg('H'))238    unmap H239  endif240  if !empty(maparg('<Space>'))241    unmap <Space>242  endif243  if !empty(maparg('<C-V>'))244    unmap <C-V>245  endif246  if !empty(maparg('f'))247    unmap f248  endif249  if !empty(maparg('<C-F>'))250    unmap <C-F>251  endif252  if !empty(maparg('z'))253    unmap z254  endif255  if !empty(maparg('<Esc><Space>'))256    unmap <Esc><Space>257  endif258  if !empty(maparg('F'))259    unmap F260  endif261  if !empty(maparg('d'))262    unmap d263  endif264  if !empty(maparg('<C-D>'))265    unmap <C-D>266  endif267  if !empty(maparg('<CR>'))268    unmap <CR>269  endif270  if !empty(maparg('<C-N>'))271    unmap <C-N>272  endif273  if !empty(maparg('e'))274    unmap e275  endif276  if !empty(maparg('<C-E>'))277    unmap <C-E>278  endif279  if !empty(maparg('j'))280    unmap j281  endif282  if !empty(maparg('<C-J>'))283    unmap <C-J>284  endif285  if !empty(maparg('b'))286    unmap b287  endif288  if !empty(maparg('<C-B>'))289    unmap <C-B>290  endif291  if !empty(maparg('w'))292    unmap w293  endif294  if !empty(maparg('<Esc>v'))295    unmap <Esc>v296  endif297  if !empty(maparg('u'))298    unmap u299  endif300  if !empty(maparg('<C-U>'))301    unmap <C-U>302  endif303  if !empty(maparg('k'))304    unmap k305  endif306  if !empty(maparg('y'))307    unmap y308  endif309  if !empty(maparg('<C-Y>'))310    unmap <C-Y>311  endif312  if !empty(maparg('<C-P>'))313    unmap <C-P>314  endif315  if !empty(maparg('<C-K>'))316    unmap <C-K>317  endif318  if !empty(maparg('r'))319    unmap r320  endif321  if !empty(maparg('<C-R>'))322    unmap <C-R>323  endif324  if !empty(maparg('R'))325    unmap R326  endif327  if !empty(maparg('g'))328    unmap g329  endif330  if !empty(maparg('<'))331    unmap <332  endif333  if !empty(maparg('<Esc><'))334    unmap <Esc><335  endif336  if !empty(maparg('G'))337    unmap G338  endif339  if !empty(maparg('>'))340    unmap >341  endif342  if !empty(maparg('<Esc>>'))343    unmap <Esc>>344  endif345  if !empty(maparg('%'))346    unmap %347  endif348  if !empty(maparg('p'))349    unmap p350  endif351  if !empty(maparg('n'))352    unmap n353  endif354  if !empty(maparg('N'))355    unmap N356  endif357  if !empty(maparg('q'))358    unmap q359  endif360  if !empty(maparg('v'))361    unmap v362  endif363  if !empty(maparg('/'))364    unmap /365  endif366  if !empty(maparg('?'))367    unmap ?368  endif369  if !empty(maparg('<Up>'))370    unmap <Up>371  endif372  if !empty(maparg('<Down>'))373    unmap <Down>374  endif375  if !empty(maparg('<PageDown>'))376    unmap <PageDown>377  endif378  if !empty(maparg('<kPageDown>'))379    unmap <kPageDown>380  endif381  if !empty(maparg('<PageUp>'))382    unmap <PageUp>383  endif384  if !empty(maparg('<kPageUp>'))385    unmap <kPageUp>386  endif387  if !empty(maparg('<S-Down>'))388    unmap <S-Down>389  endif390  if !empty(maparg('<S-Up>'))391    unmap <S-Up>392  endif393  if !empty(maparg('<Home>'))394    unmap <Home>395  endif396  if !empty(maparg('<kHome>'))397    unmap <kHome>398  endif399  if !empty(maparg('<End>'))400    unmap <End>401  endif402  if !empty(maparg('<kEnd>'))403    unmap <kEnd>404  endif405endfun406 407" vim: sw=2408 
codekingpro/portable-devtools · Team Ai