This commit is contained in:
madsenco committed 2011-01-11 15:20:06 +01:00
1 parent ebffcbed5b
commit 38a03fe357
24 files changed
+2900 -14

No files matched your search

+249
View File
@@ -0,0 +1,249 @@
" Vim script to work like "less"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last Change: 2006 Dec 05
" Avoid loading this file twice, allow the user to define his own script.
if exists("loaded_less")
finish
endif
let loaded_less = 1
" If not reading from stdin, skip files that can't be read.
" Exit if there is no file at all.
if argc() > 0
let s:i = 0
while 1
if filereadable(argv(s:i))
if s:i != 0
sleep 3
endif
break
endif
if isdirectory(argv(s:i))
echomsg "Skipping directory " . argv(s:i)
elseif getftime(argv(s:i)) < 0
echomsg "Skipping non-existing file " . argv(s:i)
else
echomsg "Skipping unreadable file " . argv(s:i)
endif
echo "\n"
let s:i = s:i + 1
if s:i == argc()
quit
endif
next
endwhile
endif
set nocp
syntax on
set so=0
set hlsearch
set incsearch
nohlsearch
" Don't remember file names and positions
set viminfo=
set nows
" Inhibit screen updates while searching
let s:lz = &lz
set lz
" Used after each command: put cursor at end and display position
if &wrap
noremap <SID>L L0:redraw<CR>:file<CR>
au VimEnter * normal! L0
else
noremap <SID>L Lg0:redraw<CR>:file<CR>
au VimEnter * normal! Lg0
endif
" When reading from stdin don't consider the file modified.
au VimEnter * set nomod
" Can't modify the text
set noma
" Give help
noremap h :call <SID>Help()<CR>
map H h
fun! s:Help()
echo "<Space> One page forward b One page backward"
echo "d Half a page forward u Half a page backward"
echo "<Enter> One line forward k One line backward"
echo "G End of file g Start of file"
echo "N% percentage in file"
echo "\n"
echo "/pattern Search for pattern ?pattern Search backward for pattern"
echo "n next pattern match N Previous pattern match"
echo "\n"
echo ":n<Enter> Next file :p<Enter> Previous file"
echo "\n"
echo "q Quit v Edit file"
let i = input("Hit Enter to continue")
endfun
" Scroll one page forward
noremap <script> <Space> :call <SID>NextPage()<CR><SID>L
map <C-V> <Space>
map f <Space>
map <C-F> <Space>
map z <Space>
map <Esc><Space> <Space>
fun! s:NextPage()
if line(".") == line("$")
if argidx() + 1 >= argc()
exe "normal! \<Esc>"
else
next
1
endif
else
exe "normal! \<C-F>"
endif
endfun
" Re-read file and page forward "tail -f"
map F :e<CR>G<SID>L:sleep 1<CR>F
" Scroll half a page forward
noremap <script> d <C-D><SID>L
map <C-D> d
" Scroll one line forward
noremap <script> <CR> <C-E><SID>L
map <C-N> <CR>
map e <CR>
map <C-E> <CR>
map j <CR>
map <C-J> <CR>
map <Down> <CR>
" Scroll one page backward
noremap <script> b <C-B><SID>L
map <C-B> b
map w b
map <Esc>v b
" Scroll half a page backward
noremap <script> u <C-U><SID>L
noremap <script> <C-U> <C-U><SID>L
" Scroll one line backward
noremap <script> k <C-Y><SID>L
map y k
map <C-Y> k
map <C-P> k
map <C-K> k
map <Up> k
" Redraw
noremap <script> r <C-L><SID>L
noremap <script> <C-R> <C-L><SID>L
noremap <script> R <C-L><SID>L
" Start of file
noremap <script> g gg<SID>L
map < g
map <Esc>< g
" End of file
noremap <script> G G<SID>L
map > G
map <Esc>> G
" Go to percentage
noremap <script> % %<SID>L
map p %
" Search
noremap <script> / H$:call <SID>Forward()<CR>/
if &wrap
noremap <script> ? H0:call <SID>Backward()<CR>?
else
noremap <script> ? Hg0:call <SID>Backward()<CR>?
endif
fun! s:Forward()
" Searching forward
noremap <script> n H$nzt<SID>L
if &wrap
noremap <script> N H0Nzt<SID>L
else
noremap <script> N Hg0Nzt<SID>L
endif
cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L
endfun
fun! s:Backward()
" Searching backward
if &wrap
noremap <script> n H0nzt<SID>L
else
noremap <script> n Hg0nzt<SID>L
endif
noremap <script> N H$Nzt<SID>L
cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L
endfun
call s:Forward()
" Quitting
noremap q :q<CR>
" Switch to editing (switch off less mode)
map v :silent call <SID>End()<CR>
fun! s:End()
set ma
if exists('s:lz')
let &lz = s:lz
endif
unmap h
unmap H
unmap <Space>
unmap <C-V>
unmap f
unmap <C-F>
unmap z
unmap <Esc><Space>
unmap F
unmap d
unmap <C-D>
unmap <CR>
unmap <C-N>
unmap e
unmap <C-E>
unmap j
unmap <Down>
unmap <C-J>
unmap b
unmap <C-B>
unmap w
unmap <Esc>v
unmap u
unmap <C-U>
unmap k
unmap <Up>
unmap y
unmap <C-Y>
unmap <C-P>
unmap <C-K>
unmap r
unmap <C-R>
unmap R
unmap g
unmap <
unmap <Esc><
unmap G
unmap >
unmap <Esc>>
unmap %
unmap p
unmap n
unmap N
unmap q
unmap v
unmap /
unmap ?
endfun
" vim: sw=2
+116
View File
@@ -0,0 +1,116 @@
" Author: fma fro Ron Aarons newfmgr.vim
let g:srcsmgrhelp= "|'o'pen, 'e'dit or 'r'eplace to edit\n|Common listing for: "
" Set up hook to Common buffers:
if 1
aug srcsmgr
au!
au BufReadPre,BufEnter CMN::*/* nested call SrcmgrReload(expand("%"))
au BufReadPre,BufEnter CMN::* nested call SrcmgrReload(expand("%"))
au BufReadPre,BufEnter GRP::* nested call SrcmgrReload(expand("%"))
au BufReadPre,BufEnter GLM::* nested call SrcmgrReload(expand("%"))
au BufReadPre,BufEnter GLW::* nested call SrcmgrReload(expand("%"))
aug END
endif
" This routine gets called when we 'edit' a directory
func! SrcmgrReload(name)
let g:vimedname = a:name
if ! exists("b:last") || (line("$")<=b:last)
call ResultsWindow('-NEW-', g:srcsmgrhelp.a:name, 'call SrcmgrInit()',
\ 'SrcmgrOnClick', 0, 'SrcmgrMap')
endif
endfunc
" This one gets called by the ResultsWindow routine on initializing the window
func! SrcmgrInit()
let b:vimedname = g:vimedname
if exists("b:last") && (line("$")>b:last)
exe (b:last+1).',$ delete _'
endif
if exists("g:CommonRes")
exe "put=g:CommonRes"
unlet g:CommonRes
else
if b:vimedname =~ "CMN::" | let Command = "Common "
elseif b:vimedname =~ "GRP::" | let Command = "Grep "
elseif b:vimedname =~ "GLM::" || b:vimedname =~ "GLW::"
if exists("g:GlimpsePath")
let Command = "glimpse-tt -H ".g:GlimpsePath." "
else
let Command = "Glimpse "
endif
if b:vimedname =~ "GLW::"
let Command = Command."-w "
endif
endif
exe "put=system(\\\"".Command."'".strpart(b:vimedname, 5, 1000)."'\\\")"
endif
set nomodified
syntax match MatchedPart /:.*/
syntax match PathPart1 "/[^/]*$"ms=s+1 contained
syntax match PathPart2 "/[^/:]*:"me=e-1,ms=s+1 contained
syntax match LeadPath "^/[^:]*"ms=s+1 contains=PathPart1,PathPart2
hi link MatchedPart Question
hi link PathPart1 Title
hi link PathPart2 Title
syntax match Hide /^|/ contained
syntax match Lead /^|.*/ contains=Hide
hi link Lead Directory
hi link Hide NonText
endfunc
" as does this, by ENTER or Dbl-click
func! SrcmgrOnClick(line)
call SrcmgrApply('e!')
endfunc
func! SrcmgrApply(what)
" get the file on which the line is
let path = substitute(getline("."), ":.*", '', '')
if path !~ '^\/'
let path = g:GlimpsePath.'/'.path
endif
if ! filereadable(path) && ! isdirectory(path)
return
endif
if b:vimedname !~ '^CMN::'
if &hlsearch == 0
aug srcsmgr
exe "au BufLeave ".path." set nohlsearch | au! srcsmgr BufLeave"
aug END
endif
set hlsearch
let @/ = strpart(b:vimedname, 5, 1000)
else
let @/ = "."
endif
if (a:what == 'new!') " create new window for file
exe 'new +/'.@/.' '.path
elseif (a:what =~ 'e!') " just edit the file
set nomodified
if a:what == 'e!!'
exe "bdelete ".bufnr("%")
endif
exe 'find +/'.@/.' '.path
else
echo 'SrcmgrApply: '.a:what.']'
endif
set readonly
endfunc
" turn special mappings on or off:
func! SrcmgrMap(on)
if a:on
nmap o :call SrcmgrApply('new!')<cr>
nmap e :call SrcmgrApply('e!')<cr>
nmap r :call SrcmgrApply('e!!')<cr>
else
unmap o
unmap e
unmap r
endif
endfunc