用户讨论:Corey:修订间差异
小 正在将页面替换为 '喜欢使用ubuntu和vim,但是都不是很了解,都在慢慢学! 最近写的一个gvim的marks脚本。方便自己方便大家! 链接 http://www.vim.org/scr...' |
小 这是一个小修改 |
||
第7行: | 第7行: | ||
[[Image:Vim marks.PNG|vim marks]] | [[Image:Vim marks.PNG|vim marks]] | ||
<br> | " ---------------------------------------------------------------------<br>" put on one sign<br>fun! Place_sign() | ||
if !exists("s:Cs_sign_number")<br> let s:Cs_sign_number = 1<br> endif | |||
if s:Cs_sign_number > 99<br> echo "Sorry, you only can use these marks less 100!"<br> return -1<br> else<br> let s:Cs_sign_number = (s:mylist[len(s:mylist) - 1][0] * 1) + 1<br> endif | |||
let vLn = "".line(".")<br> let vFileName = expand("%:p") | |||
let vFlagNum = (s:Cs_sign_number < 10 ? "0" . s:Cs_sign_number : s:Cs_sign_number)<br> let newItem = [vFlagNum,vLn,vFileName]<br> let vIndex = s:Check_list(newItem) | |||
if vIndex > -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 | |||
"let s:Cs_sign_number = s:Cs_sign_number + 1<br> let s:mylist = s:mylist + [newItem]<br> " record the last index.<br> let s:myIndex = len(s:mylist) - 1<br> let s:deleteFlag = 0<br> endif<br> "echo s:mylist<br>endfun | |||
" ---------------------------------------------------------------------<br>" Remove all signs<br>fun! Remove_all_signs() | |||
silent! exe 'sign unplace *'<br> if len(s:mylist) > 1<br> let i = remove(s:mylist, 1, -1)<br> let s:Cs_sign_number = 1<br> endif<br> "echo s:mylist<br>endfun | |||
" ---------------------------------------------------------------------<br>" Goto prev sign:<br>fun! Goto_prev_sign() | |||
if len(s:mylist) > 1<br> if s:deleteFlag == 0<br> let s:myIndex = s:myIndex - 1<br> endif<br> let s:deleteFlag = 0 | |||
if s:myIndex <= 0<br> let s:myIndex = len(s:mylist) - 1<br> endif<br> call s:Sign_jump(s:mylist[s:myIndex])<br> endif<br>endfun | |||
" ---------------------------------------------------------------------<br>" Goto next sign:<br>fun! Goto_next_sign() | |||
let s:deleteFlag = 0<br> if len(s:mylist) > 1<br> let s:myIndex = s:myIndex + 1<br> if ((s:myIndex >= len(s:mylist)) || (s:myIndex == 1))<br> let s:myIndex = 1<br> endif<br> call s:Sign_jump(s:mylist[s:myIndex])<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) | |||
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 | |||
call s:Flash_signs() | |||
"echo s:mylist<br>endfun | |||
" ---------------------------------------------------------------------<br>fun! s:Get_signs_file_name() | |||
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>" Remove one sign<br>fun! s:Remove_sign(aIndex) | |||
if len(s:mylist) > 1<br> silent! exe 'sign unplace ' .s:mylist[a:aIndex][0] . ' file=' . s:mylist[a:aIndex][2] | |||
" record the before item<br> let s:tmplist = s:mylist[a:aIndex - 1] | |||
let i = remove(s:mylist, 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> endif<br>endfun | |||
" ---------------------------------------------------------------------<br>fun! s:Flash_signs() | |||
silent! exe 'sign unplace *'<br> if len(s:mylist) > 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> let s:Cs_sign_number = s:mylist[len(s:mylist) - 1][0] * 1 + 1 <br> "let s:myIndex = 1 ##you don't need reset the pointer<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) | |||
let vResult = -1<br> let index = 0 | |||
for item in s:mylist<br> " file name is ignoring case<br> if ((s:Compare(item[1], a:aItem[1]) == 1) && (s:Compare(item[2],a:aItem[2]) == 1))<br> return index<br> endif<br> let index = index + 1<br> endfor | |||
return vResult<br>endfun | |||
" ---------------------------------------------------------------------<br>" Move_sign<br>fun! Move_sign() | |||
let s:tempItem = ["","",""]<br> let vRLn = "".line(".")<br> let vRFileName = expand("%:p") | |||
let s:tempItem[1] = vRLn<br> let s:tempItem[2] = vRFileName<br> "echo s:tempItem<br> let vRIndex = s:Check_list(s:tempItem) | |||
if (s:remarkItem[0] ==# "REMARK" )<br> if vRIndex > 0<br> silent! exe 'sign define CS' . s:mylist[vRIndex][0] . ' text='. s:mylist[vRIndex][0] .' texthl=Search'<br> silent! exe 'sign place ' . s:mylist[vRIndex][0] . ' line=' . vRLn . ' name=CS'. s:mylist[vRIndex][0] . ' file=' . vRFileName<br> let s:remarkItem = s:mylist[vRIndex]<br> let s:myIndex = vRIndex<br> "echo s:remarkItem<br> endif<br> else<br> let pionter = s:Check_list(s:remarkItem)<br> "echo vRIndex ."|" .pionter<br> if ((vRIndex < 0) && (pionter > 0))<br> silent! exe 'sign unplace ' .s:remarkItem[0] . ' file=' . s:remarkItem[2]<br> "silent! exe 'sign undefine' .s:remarkItem[0]<br> silent! exe 'sign define CS' . s:remarkItem[0] . ' text='. s:remarkItem[0] .' texthl=ErrorMsg'<br> silent! exe 'sign place ' . s:remarkItem[0] . ' line=' . vRLn . ' name=CS' . s:remarkItem[0] . ' file=' . vRFileName<br> let s:mylist[pionter][1] = vRLn<br> let s:mylist[pionter][2] = vRFileName<br> "echo s:mylist[pionter]<br> let s:myIndex = pionter<br> let s:remarkItem = ["REMARK","SEARCH","FLAG"]<br> endif<br> endif<br>endfun | |||
" -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*<br>" all of them used for the jump.<br>fun! s:Sign_jump(aSignItem)<br> let bufferExits = s:GetTabpage(a:aSignItem) | |||
if bufferExits > 0<br> silent! exe 'tabn ' . bufferExits<br> silent! exe 'sign jump '. a:aSignItem[0] . ' file='. a:aSignItem[2]<br> else<br> call s:Open_file(a:aSignItem[2])<br> silent! exe 'sign place ' . a:aSignItem[0] . ' line=' . a:aSignItem[1] . ' name=CS'. a:aSignItem[0] . ' file=' . a:aSignItem[2]<br> silent! exe 'sign jump '. a:aSignItem[0] . ' file='. a:aSignItem[2]<br> endif | |||
endfun | |||
" ---------------------------------------------------------------------<br>" GetTabpage<br>fun! s:GetTabpage(aSignItem) | |||
let bufname = expand("%:p")<br> if s:Compare(bufname,a:aSignItem[2]) == 1<br> return tabpagenr()<br> endif | |||
let i = 0 | |||
while i < tabpagenr('$') | |||
if i == 0<br> silent! exe 'tabfirst'<br> else<br> silent! exe 'tabnext'<br> endif<br> let bufname = expand("%:p") | |||
if s:Compare(bufname,a:aSignItem[2]) == 1<br> return i + 1<br> endif | |||
let i = i + 1<br> endwhile | |||
return -1<br>endfun<br>" ---------------------------------------------------------------------<br>" compare<br>fun! s:Compare(a1,a2)<br> if s:win32Flag == 1 <br> if a:a1 ==? a:a2<br> return 1<br> endif<br> else<br> if a:a1 ==# a:a2<br> return 1<br> endif<br> endif<br> return 0<br>endfun<br>" ---------------------------------------------------------------------<br>" open file<br><br> |
2008年4月14日 (一) 17:00的版本
喜欢使用ubuntu和vim,但是都不是很了解,都在慢慢学!
最近写的一个gvim的marks脚本。方便自己方便大家!
链接 http://www.vim.org/scripts/script.php?script_id=2194
" ---------------------------------------------------------------------
" put on one sign
fun! Place_sign()
if !exists("s:Cs_sign_number")
let s:Cs_sign_number = 1
endif
if s:Cs_sign_number > 99
echo "Sorry, you only can use these marks less 100!"
return -1
else
let s:Cs_sign_number = (s:mylist[len(s:mylist) - 1][0] * 1) + 1
endif
let vLn = "".line(".")
let vFileName = expand("%:p")
let vFlagNum = (s:Cs_sign_number < 10 ? "0" . s:Cs_sign_number : s:Cs_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
"let s:Cs_sign_number = s:Cs_sign_number + 1
let s:mylist = s:mylist + [newItem]
" record the last index.
let s:myIndex = len(s:mylist) - 1
let s:deleteFlag = 0
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:Cs_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
endif
let s:deleteFlag = 0
if s:myIndex <= 0
let s:myIndex = len(s:mylist) - 1
endif
call s:Sign_jump(s:mylist[s:myIndex])
endif
endfun
" ---------------------------------------------------------------------
" Goto next sign:
fun! Goto_next_sign()
let s:deleteFlag = 0
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])
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
" ---------------------------------------------------------------------
" Remove one sign
fun! s:Remove_sign(aIndex)
if len(s:mylist) > 1
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, a:aIndex)
" record the current index.
let s:myIndex = s:Check_list(s:tmplist)
let s:deleteFlag = 1
"echo s:mylist
endif
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
let s:Cs_sign_number = s:mylist[len(s:mylist) - 1][0] * 1 + 1
"let s:myIndex = 1 ##you don't need reset the pointer
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
for item in s:mylist
" file name is ignoring case
if ((s:Compare(item[1], a:aItem[1]) == 1) && (s:Compare(item[2],a:aItem[2]) == 1))
return index
endif
let index = index + 1
endfor
return vResult
endfun
" ---------------------------------------------------------------------
" Move_sign
fun! Move_sign()
let s:tempItem = ["","",""]
let vRLn = "".line(".")
let vRFileName = expand("%:p")
let s:tempItem[1] = vRLn
let s:tempItem[2] = vRFileName
"echo s:tempItem
let vRIndex = s:Check_list(s:tempItem)
if (s:remarkItem[0] ==# "REMARK" )
if vRIndex > 0
silent! exe 'sign define CS' . s:mylist[vRIndex][0] . ' text='. s:mylist[vRIndex][0] .' texthl=Search'
silent! exe 'sign place ' . s:mylist[vRIndex][0] . ' line=' . vRLn . ' name=CS'. s:mylist[vRIndex][0] . ' file=' . vRFileName
let s:remarkItem = s:mylist[vRIndex]
let s:myIndex = vRIndex
"echo s:remarkItem
endif
else
let pionter = s:Check_list(s:remarkItem)
"echo vRIndex ."|" .pionter
if ((vRIndex < 0) && (pionter > 0))
silent! exe 'sign unplace ' .s:remarkItem[0] . ' file=' . s:remarkItem[2]
"silent! exe 'sign undefine' .s:remarkItem[0]
silent! exe 'sign define CS' . s:remarkItem[0] . ' text='. s:remarkItem[0] .' texthl=ErrorMsg'
silent! exe 'sign place ' . s:remarkItem[0] . ' line=' . vRLn . ' name=CS' . s:remarkItem[0] . ' file=' . vRFileName
let s:mylist[pionter][1] = vRLn
let s:mylist[pionter][2] = vRFileName
"echo s:mylist[pionter]
let s:myIndex = pionter
let s:remarkItem = ["REMARK","SEARCH","FLAG"]
endif
endif
endfun
" -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
" all of them used for the jump.
fun! s:Sign_jump(aSignItem)
let bufferExits = s:GetTabpage(a:aSignItem)
if bufferExits > 0
silent! exe 'tabn ' . bufferExits
silent! exe 'sign jump '. a:aSignItem[0] . ' file='. a:aSignItem[2]
else
call s:Open_file(a:aSignItem[2])
silent! exe 'sign place ' . a:aSignItem[0] . ' line=' . a:aSignItem[1] . ' name=CS'. a:aSignItem[0] . ' file=' . a:aSignItem[2]
silent! exe 'sign jump '. a:aSignItem[0] . ' file='. a:aSignItem[2]
endif
endfun
" ---------------------------------------------------------------------
" GetTabpage
fun! s:GetTabpage(aSignItem)
let bufname = expand("%:p")
if s:Compare(bufname,a:aSignItem[2]) == 1
return tabpagenr()
endif
let i = 0
while i < tabpagenr('$')
if i == 0
silent! exe 'tabfirst'
else
silent! exe 'tabnext'
endif
let bufname = expand("%:p")
if s:Compare(bufname,a:aSignItem[2]) == 1
return i + 1
endif
let i = i + 1
endwhile
return -1
endfun
" ---------------------------------------------------------------------
" compare
fun! s:Compare(a1,a2)
if s:win32Flag == 1
if a:a1 ==? a:a2
return 1
endif
else
if a:a1 ==# a:a2
return 1
endif
endif
return 0
endfun
" ---------------------------------------------------------------------
" open file