用户讨论:Corey

来自Ubuntu中文
Corey留言 | 贡献2008年3月19日 (三) 16:39的版本
跳到导航跳到搜索

喜欢使用ubuntu和vim,但是都不是很了解,都在慢慢学!

" copy this file to you plugin folder.
" put below one line
" let g:Signs_file_path_corey='c:\\'
" on your gvimrc, and you can change the path.
" ---------------------------------------------------------------------

if !has("signs")
echoerr "Sorry, your vim does not support signs!"
finish
endif

if has("win32")
let s:win32Flag = 1
else
let s:win32Flag = 0
endif

"[ sign id, line number, file name]
let s:mylist = "00","0","DO NOT CHANGE ANYTHING ABOUT THE FILE, THIS USE FOR VIM PLUGIN. BY HONGLI GAO @2008/03"
let s:myIndex = 1
let s:tmplist = "00","0","corey"
let s:deleteFlag = 0
let s:outputFileName = "DO_NOT_DELETE_IT"

" ---------------------------------------------------------------------
" put on one sign
fun! Place_sign()

if !exists("s:Vm_sign_number")
let s:Vm_sign_number = 1
endif

if s:Vm_sign_number > 99
echo "Sorry, you only can use these marks less 100!"
return -1
endif

let vLn = "".line(".")
let vFileName = expand("%:p")

let vFlagNum = (s:Vm_sign_number < 10 ? "0" . s:Vm_sign_number : s:Vm_sign_number)
let newItem = [vFlagNum,vLn,vFileName]
let vIndex = s:Check_list(newItem)

if vIndex > -1
call s:Remove_sign(vIndex)
else
silent! exe 'sign define CS' . vFlagNum . ' text='. vFlagNum .' texthl=ErrorMsg'
silent! exe 'sign place ' . vFlagNum . ' line=' . vLn . ' name=CS'. vFlagNum . ' file=' . vFileName

" record the last index.
let s:myIndex = s:Vm_sign_number
let s:Vm_sign_number = s:Vm_sign_number + 1
let s:mylist = s:mylist + vFlagNum,vLn,vFileName
endif
"echo s:mylist
endfun

" ---------------------------------------------------------------------
" Remove all signs
fun! Remove_all_signs()
silent! exe 'sign unplace *'
if len(s:mylist) > 1
let i = remove(s:mylist, 1, -1)
let s:Vm_sign_number = 1
endif
"echo s:mylist
endfun

" ---------------------------------------------------------------------
" Goto prev sign:
fun! Goto_prev_sign()
if len(s:mylist) > 1
if s:deleteFlag == 0
let s:myIndex = s:myIndex - 1
else
let s:deleteFlag = 0
endif

if s:myIndex <= 0
let s:myIndex = len(s:mylist) - 1
endif
call s:Sign_jump(s:mylist[s:myIndex][0], s:mylist[s:myIndex][2])
endif
endfun

" ---------------------------------------------------------------------
" Goto next sign:
fun! Goto_next_sign()
if len(s:mylist) > 1
let s:myIndex = s:myIndex + 1
if ((s:myIndex >= len(s:mylist)) || (s:myIndex == 1))
let s:myIndex = 1
endif
call s:Sign_jump(s:mylist[s:myIndex][0], s:mylist[s:myIndex][2])
endif
endfun
" ---------------------------------------------------------------------
" Save_signs_to_file
fun! Save_signs_to_file()

call s:Get_signs_file_name()
let tempList = []
for item in s:mylist
let tempList = tempList + [item[0] . "#" . item[1]. "#" . item[2]]
endfor
let writeFlag = writefile(tempList, s:outputFileName)

endfun
" ---------------------------------------------------------------------
" Load_signs_from_file
fun! Load_signs_from_file()

call s:Get_signs_file_name()
if filereadable(s:outputFileName)
let tempList = [[]]
let iflag = 0
for line in readfile(s:outputFileName)
let first = stridx(line, "#", 0)
let second = stridx(line, "#", first + 1)
if iflag != 0
let tempList = tempList + strpart(line, 0, first), strpart(line, first + 1, second - first - 1), strpart(line, second + 1)
else
let tempList = strpart(line, 0, first), strpart(line, first + 1, second - first - 1), strpart(line, second + 1)
endif
let iflag = 1
endfor
let s:mylist = tempList
endif

call s:Flash_signs()

"echo s:mylist
endfun

" ---------------------------------------------------------------------
fun! s:Get_signs_file_name()
if exists("g:Signs_file_path_corey")
let s:outputFileName = g:Signs_file_path_corey . "_DO_NOT_DELETE_IT"
endif
endfun

" ---------------------------------------------------------------------
fun! s:Sign_jump(aSignID, aFileName)
silent! exe 'sign jump '. a:aSignID . ' file='. a:aFileName
endfun

" ---------------------------------------------------------------------
" Remove one sign
fun! s:Remove_sign(aIndex)

silent! exe 'sign unplace ' .s:mylist[a:aIndex][0] . ' file=' . s:mylist[a:aIndex][2]

" record the before item
let s:tmplist = s:mylist[a:aIndex - 1]

let i = remove(s:mylist_1, a:aIndex)

" record the current index.
let s:myIndex = s:Check_list(s:tmplist)
let s:deleteFlag = 1
"echo s:mylist
endfun

" ---------------------------------------------------------------------
fun! s:Flash_signs()

silent! exe 'sign unplace *'
if len(s:mylist) > 1
for item in s:mylist
silent! exe 'sign define CS' . item[0] . ' text='. item[0] .' texthl=ErrorMsg'
silent! exe 'sign place ' . item[0] . ' line=' . item[1] . ' name=CS'. item[0] . ' file=' . item[2]
endfor
endif
endfun

" ---------------------------------------------------------------------
" if line number and file name both same, return the aitem's index of s:mylist
" else return -1
" index 0 of s:mylist is the output message in the record file.
fun! s:Check_list(aItem)
let vResult = -1
let index = 0

if s:win32Flag == 1
for item in s:mylist
" file name is ignoring case
if ((item[1] ==? a:aItem[1]) && (item[2] ==? a:aItem[2]))
return index
endif
let index = index + 1
endfor
else
for item in s:mylist
" file name is matching case
if ((item[1] ==# a:aItem[1]) && (item[2] ==# a:aItem[2]))
return index
endif
let index = index + 1
endfor
endif

return vResult
endfun

" -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
" TODO
" I want to jump to the close file with this, but I can't now,
" so I copy these from s:Sign_jump to here. And below this function,
" all of them used for the jump.
fun! Test_open_jump()
"let bufferList = s:GetBufferList()
"echo bufferList
"let bufferExits = s:Seach_file(a:aFileName, bufferList)
"unlet bufferList
"if bufferExits >= 0
" silent! exe 'sign jump_1 '. a:aSignID . ' file='. a:aFileName
"else
"call s:Open_file(a:aFileName)
"silent! exe 'sign jump '. a:aSignID . ' file='. a:aFileName
"endif

endfun
" ---------------------------------------------------------------------
" get buffer list
fun! s:GetBufferList()

let vResult = []
let bufcount = bufnr('$')
let buflist =

" iterate through the buffers
let i = 0 | while i < bufcount | let i = i + 1
let bufname = bufname(i)

" add the name to the list
let vResult = vResult + [bufname]

endwhile
return vResult
endfun

" ---------------------------------------------------------------------
" open file
fun! s:Open_file(aFileName_1)
if tabpagenr('$') > 1
silent! exe 'tabnew '. a:aFileName
else
silent! exe 'e '. a:aFileName
endif
endfun
" ---------------------------------------------------------------------
" search file
" find the file, return the position; else return -1
fun! s:Seach_file(aFileName, aBufferList)

let vResult = -1
let index = 0

if len(a:aBufferList) > 1
if s:win32Flag == 1
for item in a:aBufferList
" file name is ignoring case
if (item ==? a:aFileName)
return index
endif
let index = index + 1
endfor
else
for item in a:aBufferList
" file name is matching case
if (item ==# a:aFileName_1)
return index
endif
let index = index + 1
endfor
endif
endif
return vResult
endfun
" ---------------------------------------------------------------------
if exists("g:Signs_file_path_corey")
let g:Signs_file_path_corey = g:Signs_file_path_corey . Pbname
call Load_signs_from_file()
endif
19,21,54,116,122,124