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

+173
View File
@@ -0,0 +1,173 @@
" File: increment.vim
" Author: Srinath Avadhanula
" Email: srinath@eecs.berkeley.edu
"
" This script provides a way to quickly create incremented lists (either
" increasing or decreasing) using the visual block mode.
"
" Synopsis:
" =========
" 1. Suppose you have a column of the following form:
" array(1) = 3;
" array(1) = 3;
" array(1) = 3;
" array(1) = 3;
" array(1) = 3;
" 2. Choose the column of '1's using Ctrl-V and then run the command Inc (you
" should see "'<,'>Inc" on the command line at this point)(if you do not
" have any other user commands starting with 'I', just I will suffice).
" This will tranform the text as:
" array(1) = 3; array(1) = 3;
" array(1) = 3; array(2) = 3;
" array(1) = 3; --> array(3) = 3;
" array(1) = 3; array(4) = 3;
" array(1) = 3; array(5) = 3;
" 3. You can then choose the column of '3's (again using Ctrl-V) and run the
" command "Inc 3" to generate another incremented list. This will
" generate:
" array(1) = 3; array(1) = 3;
" array(2) = 3; array(2) = 6;
" array(3) = 3; --> array(3) = 9;
" array(4) = 3; array(4) = 12;
" array(5) = 3; array(5) = 15;
"
"
" Note: increment.vim automatically pads the numbers in the the column
" with spaces in order to get them right aligned. This is useful in most
" cases, but for cases when this might be bad, use IncN which doesnt do
" any alignment.
"
" Commands:
" =========
" 1. Inc : generates a column of increasing numbers with RIGHT alignment.
" 2. IncN: generates a column of increasing numbers with NO alignment.
" 3. IncL: generates a column of increasing numbers with LEFT alignment
" 2. Inc : generates a column of increasing numbers with RIGHT alignment.
" 4. IncN: generates a column of increasing numbers with NO alignment.
" 6. IncL: generates a column of increasing numbers with LEFT alignment
"
" Tip:
" A mapping which goes well with this command is the following:
"
" vnoremap <c-a> :Inc<CR>
"
" With this mapping, select a column of numbers and press Ctrl-A, which will
" get them in increasing order. I use <c-a> because its similar to the <c-a>
" command in normal mode which increments the number under the cursor.
"
" Last Modification: Dec 17 2001 00:59:09
"===========================================================================
com! -ra -nargs=? Inc :call IncrementColumn(1,<args>)
com! -ra -nargs=? IncR :call IncrementColumn(2,<args>)
com! -ra -nargs=? IncN :call IncrementColumn(0,<args>)
com! -ra -nargs=? IncA :call IncrementColumn(11,<args>)
com! -ra -nargs=? IncAR :call IncrementColumn(12,<args>)
com! -ra -nargs=? IncAN :call IncrementColumn(10,<args>)
vnoremap <c-a> :Inc<CR>
"===========================================================================
function! StrRepeat(str, count)
let i = 1
let retStr = ""
while i <= a:count
let retStr = retStr.a:str
let i = i + 1
endwhile
return retStr
endfunction
" first argument is either 0 or 1 or 2 depending on whether padding with
" spaces is desired (pad = 1,2) or not. the second argument contains the
" counter increment. its optional. if not specified, its assumed to be 1.
function! IncrementColumn(pad, ...)
if a:0 == 0
let incr = 1
elseif a:0 == 1
let incr = a:1
else
return
end
let pad = a:pad
let addonly = 0
if pad >= 10
let addonly = 1
let pad = pad - 10
endif
let c1 = col("'<")
let c2 = col("'>")
let c1v = virtcol("'<")
let c2v = virtcol("'>")
let clen = c2v - c1v
if c1 > c2
let temp = c1
let c1 = c2
let c2 = temp
end
let r1 = line("'<")
let r2 = line("'>")
if r1 > r2
let temp = r1
let r1 = r2
let r2 = temp
end
exe r1
exe "let presNum = ".strpart(getline('.'), c1-1, clen+1)
let lastnum = presNum
if !addonly
let lastnum = lastnum + incr*(r2-r1)
endif
" a simple way to find the number of digits in a number (including decimal
" points, - signs etc).
let maxstrlen = strlen("".lastnum)
let r = r1
exe 'normal '.c1v.'|'
while (r <= r2)
let cnow = col(".")
let linebef = strpart(getline('.'), 0, cnow-1)
let lineaft = strpart(getline('.'), cnow+clen, 1000)
if addonly
exe "let presNum = ".strpart(getline('.'), cnow-1, clen+1)
let presNum = presNum + incr
endif
" find the number of padding spaces required for left/rigth alignment
if pad
let preslen = strlen("".presNum)
let padspace = StrRepeat(" ", maxstrlen - preslen)
else
let padspace = ""
end
" the final line is made up of
" 1. the part of the line before the number
" 2. the padding spaces.
" 3. the present number
" 4. the part of the line after the number
" the padding spaces are either before or after the current number
" depending on whether the pad argument is 1 or 2 (respectively).
if pad == 1
let lineset = linebef.padspace.presNum.lineaft
elseif pad == 2
let lineset = linebef.presNum.padspace.lineaft
else
let lineset = linebef.presNum.lineaft
end
call setline('.', lineset)
let presNum = presNum + incr
normal j
let r = r + 1
endwhile
normal `<
endfunction
+150
View File
@@ -0,0 +1,150 @@
" File: increment.vim
" Author: Srinath Avadhanula
" Email: srinath@eecs.berkeley.edu
"
" This script provides a way to quickly create incremented lists (either
" increasing or decreasing) using the visual block mode.
"
" Synopsis:
" =========
" 1. Suppose you have a column of the following form:
" array(1) = 3;
" array(1) = 3;
" array(1) = 3;
" array(1) = 3;
" array(1) = 3;
" 2. Choose the column of '1's using Ctrl-V and then run the command Inc (you
" should see "'<,'>Inc" on the command line at this point)(if you do not
" have any other user commands starting with 'I', just I will suffice).
" This will tranform the text as:
" array(1) = 3; array(1) = 3;
" array(1) = 3; array(2) = 3;
" array(1) = 3; --> array(3) = 3;
" array(1) = 3; array(4) = 3;
" array(1) = 3; array(5) = 3;
" 3. You can then choose the column of '3's (again using Ctrl-V) and run the
" command "Inc 3" to generate another incremented list. This will
" generate:
" array(1) = 3; array(1) = 3;
" array(2) = 3; array(2) = 6;
" array(3) = 3; --> array(3) = 9;
" array(4) = 3; array(4) = 12;
" array(5) = 3; array(5) = 15;
"
" Note: increment.vim automatically pads the numbers in the the column
" with spaces in order to get them right aligned. This is useful in most
" cases, but for cases when this might be bad, use IncN which doesnt do
" any alignment.
"
" Commands:
" =========
" 1. Inc : generates a column of increasing numbers with RIGHT alignment.
" 2. IncN: generates a column of increasing numbers with NO alignment.
" 3. IncL: generates a column of increasing numbers with LEFT alignment
"
" Tip:
" A mapping which goes well with this command is the following:
"
" vnoremap <c-a> :Inc<CR>
"
" With this mapping, select a column of numbers and press Ctrl-A, which will
" get them in increasing order. I use <c-a> because its similar to the <c-a>
" command in normal mode which increments the number under the cursor.
"
" Last Modification: Dec 17 2001 00:59:09
"===========================================================================
com! -ra -nargs=? Inc :call IncrementColumn(1,<args>)
com! -ra -nargs=? IncR :call IncrementColumn(2,<args>)
com! -ra -nargs=? IncN :call IncrementColumn(0,<args>)
"===========================================================================
function! StrRepeat(str, count)
let i = 1
let retStr = ""
while i <= a:count
let retStr = retStr.a:str
let i = i + 1
endwhile
return retStr
endfunction
" first argument is either 0 or 1 or 2 depending on whether padding with
" spaces is desired (pad = 1,2) or not. the second argument contains the
" counter increment. its optional. if not specified, its assumed to be 1.
function! IncrementColumn(pad, ...)
if a:0 == 0
let incr = 1
elseif a:0 == 1
let incr = a:1
else
return
end
let c1 = col("'<")
let c2 = col("'>")
let c1v = virtcol("'<")
let c2v = virtcol("'>")
let clen = c2v - c1v
if c1 > c2
let temp = c1
let c1 = c2
let c2 = temp
end
let r1 = line("'<")
let r2 = line("'>")
if r1 > r2
let temp = r1
let r1 = r2
let r2 = temp
end
exe r1
exe "let presNum = ".strpart(getline('.'), c1-1, clen+1)
let lastnum = presNum + incr*(r2-r1)
" a simple way to find the number of digits in a number (including decimal
" points, - signs etc).
let maxstrlen = strlen("".lastnum)
let r = r1
exe 'normal '.c1v.'|'
while (r <= r2)
let cnow = col(".")
let linebef = strpart(getline('.'), 0, cnow-1)
let lineaft = strpart(getline('.'), cnow+clen, 1000)
" find the number of padding spaces required for left/rigth alignment
if a:pad
let preslen = strlen("".presNum)
let padspace = StrRepeat(" ", maxstrlen - preslen)
else
let padspace = ""
end
" the final line is made up of
" 1. the part of the line before the number
" 2. the padding spaces.
" 3. the present number
" 4. the part of the line after the number
" the padding spaces are either before or after the current number
" depending on whether the pad argument is 1 or 2 (respectively).
if a:pad == 1
let lineset = linebef.padspace.presNum.lineaft
elseif a:pad == 2
let lineset = linebef.presNum.padspace.lineaft
else
let lineset = linebef.presNum.lineaft
end
call setline('.', lineset)
let presNum = presNum + incr
normal j
let r = r + 1
endwhile
normal `<
endfunction
+90
View File
@@ -0,0 +1,90 @@
" Vim global plugin for javadoc comment wrangling
" Maintainer: fm@amplex.dk
if exists("g:loaded_jdocConvert")
" finish
endif
let g:loaded_jdocConvert = 1
let s:save_cpo = &cpo
set cpo&vim
let &cpo = s:save_cpo
if !hasmapto('<Plug>jdocConvertCompact')
map <unique> <Leader>jc <Plug>jdocConvertCompact
endif
noremap <unique> <script> <Plug>jdocConvertCompact <SID>ConvertCompact
if !hasmapto('<Plug>jdocConvertHere')
map <unique> <Leader>jh <Plug>jdocConvertHere
endif
noremap <unique> <script> <Plug>jdocConvertHere <SID>ConvertHere
function! s:JdocConvert(type, rng1, rng2) range
let [rng1, rng2] = [a:rng1, a:rng2]
if rng2 < rng1
let [rng2,rng1] = [rng1,rng2]
end
let rng2 = max([rng1 + 3, rng2])
let inp = getline(rng1, rng2)
let out = []
let txt = []
let inside = -1
let did_subst = 0
let lead = ""
let lno = rng2 - rng1
for line in inp
if line =~ '^\s*/\*\*'
" Start jdoc
let inside = 1
let lead = substitute(line, '/\*\*.*$', "", "")
elseif line =~ '^\s*\* ' && inside > 0
" Inline jdoc
call add(txt, substitute(line, '^\s*\* ', "", ""))
elseif line =~ '^\s*\*/'
" End jdoc
let inside = 0
if a:type == 1
for l in txt
call add(out, lead.'/// '.l)
endfor
let txt = []
let did_subst = 1
end
elseif len(txt) > 0 && a:type == 2
" Place text on first
call add(out, line.' ///< '.txt[0])
call remove(txt, 0)
let did_subst = 1
if len(txt) > 0
let lead = repeat(" ", len(line)).' ///< '
for l in txt
call add(out, lead.l)
endfor
endif
let txt = []
else
" Copy over
call add(out, line)
endif
let lno += 1
endfor
if did_subst
exe rng1.",".rng2 " delete"
call append(rng1 - 1, out)
exe rng1 - 1 + len(out)
endif
endfunction
function! s:CallConvert(bang, l1, l2)
let type = a:bang == "!" ? 1 : 2
call s:JdocConvert(type, a:l1, a:l2)
endfunction
nnoremap <SID>ConvertCompact :call <SID>JdocConvert(1, line("."), line(".") + v:count1 - 1)<CR>
nnoremap <SID>ConvertHere :call <SID>JdocConvert(2, line("."), line(".") + v:count1 - 1)<CR>
vnoremap <SID>ConvertCompact :call <SID>JdocConvert(1, line("'<"), line("'>"))<CR>
vnoremap <SID>ConvertHere :call <SID>JdocConvert(2, line("'<"), line("'>"))<CR>
command! -bang -range JdocConvert :call s:CallConvert("<bang>", <line1>, <line2>)
let &cpo = s:save_cpo
File diff suppressed because it is too large. Load diff
+258
View File
@@ -0,0 +1,258 @@
" collection of misc code I find useful
" Author: Ron Aaron ron@mossbayeng.com
"
" 'if 0'ed' everything outside the StatusWindow stuff /fma
"
" last update: Sun Jul 11 14:42:38 1999
if 0
set nocp
let g:utils_package_loaded = 1
" define whatever this package does, here
func! SetIfBlank(var, value)
let value = a:value
if !exists(a:var)
if match(a:value, '^expand') >= 0
" expand it
exe 'let value=' a:value
let value=escape(value, '\')
endif
exe 'let ' a:var '= "'. value .'"'
endif
endfunc
command! -nargs=* SetIfBlank call SetIfBlank(<f-args>)
" convert a number or bool to a portion of the passed-in string
func! ValueToString(choices, value, bool)
let retval = '<unknown>'
" first, convert the 'value' to an index:
if (a:bool)
" boolean. 0 == 'n' == 'No' == 'false'
if a:value=~"[a-zA-Z]"
if ((a:value =~ "^[nN]o*") || (a:value=~"^[Ff][aA][lL][sS][eE]"))
let index = 0
else
let index = 1
endif
else
let index = !(a:value == 0)
endif
else
" force numeric.
let index = 0 + a:value
endif
" second, find the 'index'th string in 'choices', which should be a
" comma-delmited string
let x=0
let choice=a:choices
while 1
if (x == index) " that's our boy!
let ix = match(choice, ',')
" extract the string up till the comma
if ix == -1
let ix = 99999
endif
let retval = strpart(choice, 0, ix)
return retval
endif
" get next string part
let ix = match(choice, ',')
if ix == -1
" failed!
return retval
endif
let choice = strpart(choice, ix+1, 99999)
" bump counter
let x = x+1
endwhile
endfunc
" convert a number or bool to a portion of the passed-in string
func! BoolString(bool)
return ValueToString('no,yes', a:bool, 1)
endfunc
endif
func! Fnmunge(name)
let name = substitute(a:name,'[\\/ \t:]', '', 'g')
return name
endfunc
func! On_(true)
if a:true | return "no" | else | return "" | endif
endfunc
func! ResultsWindow (name,help,cmd,action,once,maps)
" turn off reporting
let rep=&report | let mo=On_(&more) | let ch=&ch | let te=On_(&terse)
set report=9999 nomore ch=3 hidden terse
let retval=0
if exists("b:origbuf")
let origbuf = b:origbuf
elseif a:name == '-NEW-'
let origbuf = bufnr(@#)
else
let origbuf = bufnr("")
endif
let b:samebuf=0
if (a:name == '')
let b:samebuf=1
% d _
elseif a:name == '-NEW-'
% d _
else
let name=g:home.'/'.Fnmunge(a:name)
exe 'new ' . name
endif
let b:origbuf = origbuf
let b:resultswindow=1
let b:action = a:action
let b:once = a:once
let b:maps = a:maps " additional map function (one parm: 1=on, 0=off)
0 put=a:help
let b:last = line("$") " save last line number
normal G
" fill in the buffer with something:
exe a:cmd
if v:shell_error < 0
if !b:samebuf
unlet b:resultswindow
bdelete!
endif
echo 'Problem executing command: ' . a:cmd . ':' . v:errmsg
return
endif
let last=line("$") " get new last line number...
if (b:last == last) || ((last ==(b:last+1)) && getline(last)=='') "nothing!!!
if !b:samebuf
unlet b:resultswindow
bdelete!
endif
elseif last == (b:last+1) " one more line
let b:once=1
call ResultsMap(1)
call ResultsAct(last)
let retval=1
else " more than one ... set up window
normal 1zt
" exe 'normal ' . b:last . 'j'
set nomod
let retval=2
call ResultsMap(1)
endif
exe "set ".mo."more ".te."terse"." ch=".ch." report=".rep
return retval
endfunc
func! ResultsAct (lineno)
if (a:lineno <= b:last) " in header
return
else
let line=escape(getline(a:lineno),"'\"")
let buffer=bufnr("")
let action=b:action
let origbuf = b:origbuf
let dodelete = b:once && !b:samebuf
"see if action is a function:
if exists("*".action)
" yes, so 'call'
let act='call '.action."('".line."')"
exe act
elseif (action != '')
" no, just exe
exe action . ' ' . line
endif
if dodelete
exe 'bdelete! '.buffer
let buffer=bufnr("")
" Reestablish alternate file
exe 'buffer '.origbuf
exe 'buffer '.buffer
endif
endif
endfunc
func! ResultsMap (on)
if (a:on)
map <cr> :call ResultsAct(line("."))<cr>
map <2-LeftMouse> <cr>
if (exists("b:maps") && b:maps != '')
exe 'call' b:maps . '(1)'
endif
else
if mapcheck("<cr>")!=''
unmap <2-LeftMouse>
unmap <cr>
endif
if (exists("b:maps") && b:maps != '')
exe 'call' b:maps . '(0)'
endif
endif
endfunc
aug ResultsWindow
au!
au BufEnter * :if exists("b:resultswindow")|:call ResultsMap(1)|:endif
au BufLeave * :if exists("b:resultswindow")|:call ResultsMap(0)|:endif
au VimLeavePre * :call ResultsCleanup()
aug END
func! ResultsCleanup()
let ix = 1
while ix <= bufnr("$")
" NOTE: 'getbufvar' is my enhancement, you need my patches!
if exists("*getbufvar") && getbufvar(ix,'resultswindow')
exe 'bd '.ix
elseif match(bufname(ix), '-results-') >= 0
exe 'bd '.ix
endif
let ix = ix + 1
endwhile
endfunc
if 0
" we need 'g:vimlocal', so create it if not present
if !exists("g:vimlocal")
let g:vimlocal = expand("~") . '/vimscripts'
endif
func! SourceIfReadable(filename)
let retcode=1
if filereadable(g:vimlocal . '/' . a:filename)
exe 'so ' . g:vimlocal . '/' . a:filename
elseif filereadable($VIM . '/' . a:filename)
exe 'so ' . $VIM . '/' . a:filename
elseif filereadable(a:filename)
exe 'so ' . a:filename
else
let retcode=0
endif
return retcode
endfunc
command! -nargs=1 Source call SourceIfReadable(<q-args>)
func! Require(package)
let shortname = fnamemodify(a:package, ':r')
if !exists("g:".shortname.'_package_loaded')
" loads 'package'. First looks in 'vimscripts'
if !SourceIfReadable(a:package)
echo "Error! Cannot load required package " . a:package
endif
endif
endfunc
command! -nargs=1 Require call Require(<q-args>)
SetIfBlank g:home expand("~")
endif