个人工具

“用户讨论:Corey”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(正在将页面替换为 '喜欢使用ubuntu和vim,但是都不是很了解,都在慢慢学!')
第1行: 第1行:
 
喜欢使用ubuntu和vim,但是都不是很了解,都在慢慢学!
 
喜欢使用ubuntu和vim,但是都不是很了解,都在慢慢学!
 +
 +
" copy this file to you plugin folder.<br>" put below one line <br>" let g:Signs_file_path_corey='c:\\'<br>" on your gvimrc, and you can change the path.<br>" ---------------------------------------------------------------------
 +
 +
if !has("signs")<br> echoerr "Sorry, your vim does not support signs!"<br> finish<br>endif
 +
 +
if has("win32")<br> let s:win32Flag = 1<br>else<br> let s:win32Flag = 0<br>endif
 +
 +
"[ sign id, line number, file name]<br>let s:mylist = [["00","0","DO NOT CHANGE ANYTHING ABOUT THE FILE, THIS USE FOR VIM PLUGIN. BY HONGLI GAO @2008/03"]]<br>let s:myIndex = 1<br>let s:tmplist = [["00","0","corey"]]<br>let s:deleteFlag = 0<br>let s:outputFileName = "DO_NOT_DELETE_IT"
 +
 +
" ---------------------------------------------------------------------<br>" put on one sign<br>fun! Place_sign()
 +
 +
if !exists("s:Vm_sign_number")<br> let s:Vm_sign_number = 1<br> endif
 +
 +
if s:Vm_sign_number &gt; 99 <br> echo "Sorry, you only can use these marks less 100!"<br> return -1<br> endif
 +
 +
let vLn = "".line(".")<br> let vFileName = expand("%:p")
 +
 +
let vFlagNum = (s:Vm_sign_number &lt; 10 ? "0" . s:Vm_sign_number : s:Vm_sign_number)<br> let newItem = [vFlagNum,vLn,vFileName]<br> let vIndex = s:Check_list(newItem)
 +
 +
if vIndex &gt; -1 <br> call s:Remove_sign(vIndex)<br> else <br> silent! exe 'sign define CS' . vFlagNum . ' text='. vFlagNum .' texthl=ErrorMsg'<br> silent! exe 'sign place ' . vFlagNum . ' line=' . vLn . ' name=CS'. vFlagNum . ' file=' . vFileName
 +
 +
" record the last index.<br> let s:myIndex = s:Vm_sign_number<br> let s:Vm_sign_number = s:Vm_sign_number + 1<br> let s:mylist = s:mylist + [[vFlagNum,vLn,vFileName]]<br> endif <br> "echo s:mylist<br>endfun
 +
 +
" ---------------------------------------------------------------------<br>" Remove all signs<br>fun! Remove_all_signs()<br> silent! exe 'sign unplace *'<br> if len(s:mylist) &gt; 1 <br> let i = remove(s:mylist, 1, -1)<br> let s:Vm_sign_number = 1<br> endif<br> "echo s:mylist<br>endfun
 +
 +
" ---------------------------------------------------------------------<br>" Goto prev sign:<br>fun! Goto_prev_sign()<br> if len(s:mylist) &gt; 1<br> if s:deleteFlag == 0 <br> let s:myIndex = s:myIndex - 1<br> else<br> let s:deleteFlag = 0 <br> endif<br> <br> if s:myIndex &lt;= 0<br> let s:myIndex = len(s:mylist) - 1<br> endif<br> call s:Sign_jump(s:mylist[s:myIndex][0], s:mylist[s:myIndex][2])<br> endif<br>endfun
 +
 +
" ---------------------------------------------------------------------<br>" Goto next sign:<br>fun! Goto_next_sign()<br> if len(s:mylist) &gt; 1<br> let s:myIndex = s:myIndex + 1<br> if ((s:myIndex &gt;= len(s:mylist)) || (s:myIndex == 1))<br> let s:myIndex = 1<br> endif<br> call s:Sign_jump(s:mylist[s:myIndex][0], s:mylist[s:myIndex][2])<br> endif<br>endfun<br>" ---------------------------------------------------------------------<br>" Save_signs_to_file<br>fun! Save_signs_to_file()
 +
 +
call s:Get_signs_file_name()<br> let tempList = []<br> for item in s:mylist<br> let tempList = tempList + [item[0] . "#" . item[1]. "#" . item[2]]<br> endfor<br> let writeFlag = writefile(tempList, s:outputFileName)<br> <br>endfun<br>" ---------------------------------------------------------------------<br>" Load_signs_from_file<br>fun! Load_signs_from_file()
 +
 +
call s:Get_signs_file_name()<br> if filereadable(s:outputFileName)<br> let tempList = [[]]<br> let iflag = 0<br> for line in readfile(s:outputFileName)<br> let first = stridx(line, "#", 0)<br> let second = stridx(line, "#", first + 1)<br> if iflag != 0 <br> let tempList = tempList + [[strpart(line, 0, first), strpart(line, first + 1, second - first - 1), strpart(line, second + 1)]]<br> else<br> let tempList = [[strpart(line, 0, first), strpart(line, first + 1, second - first - 1), strpart(line, second + 1)]]<br> endif<br> let iflag = 1<br> endfor<br> let s:mylist = tempList<br> endif<br> <br> call s:Flash_signs()
 +
 +
"echo s:mylist <br>endfun
 +
 +
" ---------------------------------------------------------------------<br>fun! s:Get_signs_file_name()<br> if exists("g:Signs_file_path_corey")<br> let s:outputFileName = g:Signs_file_path_corey . "_DO_NOT_DELETE_IT"<br> endif<br>endfun
 +
 +
" ---------------------------------------------------------------------<br>fun! s:Sign_jump(aSignID, aFileName)<br> silent! exe 'sign jump '. a:aSignID . ' file='. a:aFileName<br>endfun
 +
 +
" ---------------------------------------------------------------------<br>" Remove one sign<br>fun! s:Remove_sign(aIndex)
 +
 +
silent! exe 'sign unplace ' .s:mylist[a:aIndex][0] . ' file=' . s:mylist[a:aIndex][2]<br> <br> " record the before item<br> let s:tmplist = s:mylist[a:aIndex - 1]<br> <br> let i = remove(s:mylist_1, a:aIndex)
 +
 +
" record the current index.<br> let s:myIndex = s:Check_list(s:tmplist) <br> let s:deleteFlag = 1<br> "echo s:mylist<br>endfun
 +
 +
" ---------------------------------------------------------------------<br>fun! s:Flash_signs()<br> <br> silent! exe 'sign unplace *'<br> if len(s:mylist) &gt; 1 <br> for item in s:mylist<br> silent! exe 'sign define CS' . item[0] . ' text='. item[0] .' texthl=ErrorMsg'<br> silent! exe 'sign place ' . item[0] . ' line=' . item[1] . ' name=CS'. item[0] . ' file=' . item[2]<br> endfor<br> endif<br>endfun
 +
 +
" ---------------------------------------------------------------------<br>" if line number and file name both same, return the aitem's index of s:mylist<br>" else return -1<br>" index 0 of s:mylist is the output message in the record file.<br>fun! s:Check_list(aItem)<br> let vResult = -1<br> let index = 0
 +
 +
if s:win32Flag == 1<br> for item in s:mylist<br> " file name is ignoring case<br> if ((item[1] ==? a:aItem[1]) &amp;&amp; (item[2] ==? a:aItem[2]))<br> return index<br> endif<br> let index = index + 1<br> endfor<br> else<br> for item in s:mylist<br> " file name is matching case<br> if ((item[1] ==# a:aItem[1]) &amp;&amp; (item[2] ==# a:aItem[2]))<br> return index<br> endif<br> let index = index + 1<br> endfor<br> endif
 +
 +
return vResult<br>endfun
 +
 +
" -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*<br>" TODO<br>" I want to jump to the close file with this, but I can't now,<br>" so I copy these from s:Sign_jump to here. And below this function,<br>" all of them used for the jump.<br>fun! Test_open_jump()<br> "let bufferList = s:GetBufferList()<br> "echo bufferList<br> "let bufferExits = s:Seach_file(a:aFileName, bufferList)<br> "unlet bufferList<br> "if bufferExits &gt;= 0 <br> " silent! exe 'sign jump_1 '. a:aSignID . ' file='. a:aFileName<br> "else<br> "call s:Open_file(a:aFileName)<br> "silent! exe 'sign jump '. a:aSignID . ' file='. a:aFileName<br> "endif
 +
 +
endfun<br>" ---------------------------------------------------------------------<br>" get buffer list <br>fun! s:GetBufferList()<br> <br> let vResult = []<br> let bufcount = bufnr('$')<br> let buflist = ''
 +
 +
" iterate through the buffers<br> let i = 0 | while i &lt; bufcount | let i = i + 1<br> let bufname = bufname(i)
 +
 +
" add the name to the list<br> let vResult = vResult + [bufname]
 +
 +
endwhile<br> return vResult<br>endfun
 +
 +
" ---------------------------------------------------------------------<br>" open file<br>fun! s:Open_file(aFileName_1)<br> if tabpagenr('$') &gt; 1 <br> silent! exe 'tabnew '. a:aFileName<br> else<br> silent! exe 'e '. a:aFileName<br> endif<br>endfun<br>" ---------------------------------------------------------------------<br>" search file<br>" find the file, return the position; else return -1<br>fun! s:Seach_file(aFileName, aBufferList)
 +
 +
let vResult = -1<br> let index = 0
 +
 +
if len(a:aBufferList) &gt; 1 <br> if s:win32Flag == 1<br> for item in a:aBufferList<br> " file name is ignoring case<br> if (item ==? a:aFileName)<br> return index<br> endif<br> let index = index + 1<br> endfor<br> else<br> for item in a:aBufferList<br> " file name is matching case<br> if (item ==# a:aFileName_1)<br> return index<br> endif<br> let index = index + 1<br> endfor<br> endif <br> endif<br> return vResult<br>endfun<br>" ---------------------------------------------------------------------<br> if exists("g:Signs_file_path_corey") <br> let g:Signs_file_path_corey = g:Signs_file_path_corey . Pbname <br> call Load_signs_from_file()<br> endif<br>19,21,54,116,122,124<br><br>

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