查看“用户讨论:Corey”的源代码
来自Ubuntu中文
←
用户讨论:Corey
跳到导航
跳到搜索
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
喜欢使用ubuntu和vim,但是都不是很了解,都在慢慢学! 最近写的一个gvim的marks脚本。方便自己方便大家! 链接 http://www.vim.org/scripts/script.php?script_id=2194<br> [[Image:Vim marks.PNG|vim marks]] " ---------------------------------------------------------------------<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>
返回
用户讨论:Corey
。
导航菜单
页面操作
用户页
讨论
阅读
查看源代码
历史
页面操作
用户页
讨论
更多
工具
个人工具
登录
导航
首页
最近更改
随机页面
页面分类
帮助
搜索
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
用户贡献
日志
查看用户组
特殊页面
页面信息