个人工具

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

来自Ubuntu中文

跳转至: 导航, 搜索
(正在将页面替换为 '喜欢使用ubuntu和vim,但是都不是很了解,都在慢慢学! 最近写的一个gvim的marks脚本。方便自己方便大家! 链接 http://www.vim.org/scr...')
 
(未显示同一用户的7个中间版本)
第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>" ---------------------------------------------------------------------
+
最近写的一个gvim的marks脚本。方便自己方便大家!
  
if !has("signs")<br> echoerr "Sorry, your vim does not support signs!"<br> finish<br>endif
+
链接 http://www.vim.org/scripts/script.php?script_id=2194<br>
  
if has("win32")<br> let s:win32Flag = 1<br>else<br> let s:win32Flag = 0<br>endif
+
[[Image:Vim marks.PNG|vim marks]]
  
"[ 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
+
<br>
 
+
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年4月14日 (一) 20:52的最新版本

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

最近写的一个gvim的marks脚本。方便自己方便大家!

链接 http://www.vim.org/scripts/script.php?script_id=2194

vim marks