个人工具

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

来自Ubuntu中文

跳转至: 导航, 搜索
(正在将页面替换为 '喜欢使用ubuntu和vim,但是都不是很了解,都在慢慢学! <br>')
第1行: 第1行:
 
喜欢使用ubuntu和vim,但是都不是很了解,都在慢慢学!
 
喜欢使用ubuntu和vim,但是都不是很了解,都在慢慢学!
  
 +
if !has("signs")s1gns echoerr "Sorry, your vim does not support signs!"<br> finishs1gns endif
  
 +
"[ sign id, line number, file name]s1gns let s:mylist = [["00","0","DO NOT CHANGE ANYTHING ABOUT THE FILE"]]<br>let s:myIndex = 1s1gns let s:tmplist = [["00","0","corey"]]<br>let s:deleteFlag = 0s1gns <br>" ---------------------------------------------------------------------<br>" maping the keyboard <br>if !hasmapto('&lt;Plug&gt;Place_sign')s1gns map &lt;unique&gt; &lt;c-F2&gt; &lt;Plug&gt;Place_sign<br> map &lt;silent&gt; &lt;unique&gt; mm &lt;Plug&gt;Place_sign <br>endif<br>nnoremap &lt;silent&gt; &lt;script&gt; &lt;Plug&gt;Place_sign :call Place_sign()&lt;cr&gt;
 +
 +
if !hasmapto('&lt;Plug&gt;Goto_next_sign')s1gns map &lt;unique&gt; &lt;F2&gt; &lt;Plug&gt;Goto_next_sign<br> map &lt;silent&gt; &lt;unique&gt; m. &lt;Plug&gt;Goto_next_sign <br>endif<br>nnoremap &lt;silent&gt; &lt;script&gt; &lt;Plug&gt;Goto_next_sign :call Goto_next_sign()&lt;cr&gt;
 +
 +
if !hasmapto('&lt;Plug&gt;Goto_prev_sign')s1gns map &lt;unique&gt; &lt;s-F2&gt; &lt;Plug&gt;Goto_prev_sign<br> map &lt;silent&gt; &lt;unique&gt; mv &lt;Plug&gt;Goto_prev_sign <br>endif<br>nnoremap &lt;silent&gt; &lt;script&gt; &lt;Plug&gt;Goto_prev_sign :call Goto_prev_sign()&lt;cr&gt;
 +
 +
if !hasmapto('&lt;Plug&gt;Remove_all_signs')s1gns map &lt;unique&gt; &lt;F4&gt; &lt;Plug&gt;Remove_all_signs<br>endif<br>nnoremap &lt;silent&gt; &lt;script&gt; &lt;Plug&gt;Remove_all_signs :call Remove_all_signs()&lt;cr&gt;
 +
 +
" ---------------------------------------------------------------------<br>" put on one sign<br>fun! Place_sign()s1gns <br> if !exists("s:Sign_num")s1gns let s:Sign_num = 1<br> endifs1gns <br> if s:Sign_num &gt; 99 s1gns echo "Sorry, you only can use these marks less 100!"<br> return -1s1gns endif<br>s1gns let vLn = "".line(".")<br> let vFileName = expand("%:p")s1gns <br> let vFlagNum = (s:Sign_num &lt; 10 ? "0" . s:Sign_num : s:Sign_num)s1gns let newItem = [vFlagNum,vLn,vFileName]<br> "echo newItem s1gns let vIndex = s:Check_list(newItem)<br> "echo vIndexs1gns if vIndex &gt; -1 <br> call s:Remove_sign(vIndex)s1gns else <br> "exec 'sign define CS' . vFlagNum . ' text='. vFlagNum .' linehl=NONE texthl=ErrorMsg's1gns exec 'sign define CS' . vFlagNum . ' text='. vFlagNum .' texthl=ErrorMsg'<br>s1gns "exe 'sign place ' . b:Sign_num . ' line=' . ln . ' name=CS'. FlagNum . ' buffer=' . winbufnr(0)<br> exe 'sign place ' . vFlagNum . ' line=' . vLn . ' name=CS'. vFlagNum . ' file=' . vFileNames1gns <br> " record the last index.s1gns let s:myIndex = s:Sign_num<br> let s:Sign_num = s:Sign_num + 1s1gns let s:mylist = s:mylist + [[vFlagNum,vLn,vFileName]]<br> endif s1gns "echo s:mylist<br> "unlet newItem<br>endfun
 +
 +
" ---------------------------------------------------------------------<br>" Remove one sign<br>fun! s:Remove_sign(aIndex)s1gns <br> silent! exe 'sign unplace ' .s:mylist[a:aIndex][0] . ' file=' . s:mylist[a:aIndex][2]s1gns "echo 'sign unplace ' .s:mylist[a:aIndex][0] . ' file=' . s:mylist[a:aIndex][2]<br> s1gns " record the before item<br> let s:tmplist = s:mylist[a:aIndex - 1]s1gns <br> let i = remove(s:mylist, a:aIndex)s1gns <br> " record the current index.s1gns let s:myIndex = s:Check_list(s:tmplist) <br> let s:deleteFlag = 1s1gns "echo s:mylist<br>endfun
 +
 +
" ---------------------------------------------------------------------<br>" Remove all signs<br>fun! Remove_all_signs()s1gns silent! exe 'sign unplace *'<br> if len(s:mylist) &gt; 1 s1gns let i = remove(s:mylist, 1, -1)<br> let s:Sign_num = 1s1gns endif<br> "echo s:mylist<br>endfun
 +
 +
<br>" ---------------------------------------------------------------------<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)s1gns let vResult = -1<br> let index = 0s1gns <br> for item in s:mylists1gns "echo item[1] . "-" . a:aItem[1] . "=" . item[2] . "-" . a:aItem[2]<br> if ((item[1] ==? a:aItem[1]) &amp;&amp; (item[2] ==? a:aItem[2]))s1gns return index<br> endifs1gns let index = index + 1<br> endfors1gns <br> return vResult<br>endfun
 +
 +
" ---------------------------------------------------------------------<br>" Goto prev sign:<br>fun! Goto_prev_sign()s1gns if len(s:mylist) &gt; 1<br> if s:deleteFlag == 0 s1gns let s:myIndex = s:myIndex - 1<br> elses1gns let s:deleteFlag = 0 <br> endifs1gns <br> if s:myIndex &lt;= 0s1gns let s:myIndex = len(s:mylist) - 1<br> endifs1gns silent! exe 'sign jump '. s:mylist[s:myIndex][0] . ' file='. s:mylist[s:myIndex][2]<br> "echo 'sign jump '. s:mylist[s:myIndex][0] . ' file='. s:mylist[s:myIndex][2]s1gns endif<br>endfun
 +
 +
" ---------------------------------------------------------------------<br>" Goto next sign:<br>fun! Goto_next_sign()s1gns if len(s:mylist) &gt; 1<br> let s:myIndex = s:myIndex + 1s1gns if ((s:myIndex &gt;= len(s:mylist)) || (s:myIndex == 1))<br> let s:myIndex = 1s1gns endif<br> silent! exe 'sign jump '. s:mylist[s:myIndex][0] . ' file='. s:mylist[s:myIndex][2]s1gns "echo 'sign jump '. s:mylist[s:myIndex][0] . ' file='. s:mylist[s:myIndex][2]<br> endif<br>endfun
 +
 +
" ---------------------------------------------------------------------<br><br>
 +
 +
<br>
  
 
<br>
 
<br>

2008年3月18日 (二) 16:54的版本

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

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

"[ sign id, line number, file name]s1gns let s:mylist = "00","0","DO NOT CHANGE ANYTHING ABOUT THE FILE"
let s:myIndex = 1s1gns let s:tmplist = "00","0","corey"
let s:deleteFlag = 0s1gns
" ---------------------------------------------------------------------
" maping the keyboard
if !hasmapto('<Plug>Place_sign')s1gns map <unique> <c-F2> <Plug>Place_sign
map <silent> <unique> mm <Plug>Place_sign
endif
nnoremap <silent> <script> <Plug>Place_sign :call Place_sign()<cr>

if !hasmapto('<Plug>Goto_next_sign')s1gns map <unique> <F2> <Plug>Goto_next_sign
map <silent> <unique> m. <Plug>Goto_next_sign
endif
nnoremap <silent> <script> <Plug>Goto_next_sign :call Goto_next_sign()<cr>

if !hasmapto('<Plug>Goto_prev_sign')s1gns map <unique> <s-F2> <Plug>Goto_prev_sign
map <silent> <unique> mv <Plug>Goto_prev_sign
endif
nnoremap <silent> <script> <Plug>Goto_prev_sign :call Goto_prev_sign()<cr>

if !hasmapto('<Plug>Remove_all_signs')s1gns map <unique> <F4> <Plug>Remove_all_signs
endif
nnoremap <silent> <script> <Plug>Remove_all_signs :call Remove_all_signs()<cr>

" ---------------------------------------------------------------------
" put on one sign
fun! Place_sign()s1gns
if !exists("s:Sign_num")s1gns let s:Sign_num = 1
endifs1gns
if s:Sign_num > 99 s1gns echo "Sorry, you only can use these marks less 100!"
return -1s1gns endif
s1gns let vLn = "".line(".")
let vFileName = expand("%:p")s1gns
let vFlagNum = (s:Sign_num < 10 ? "0" . s:Sign_num : s:Sign_num)s1gns let newItem = [vFlagNum,vLn,vFileName]
"echo newItem s1gns let vIndex = s:Check_list(newItem)
"echo vIndexs1gns if vIndex > -1
call s:Remove_sign(vIndex)s1gns else
"exec 'sign define CS' . vFlagNum . ' text='. vFlagNum .' linehl=NONE texthl=ErrorMsg's1gns exec 'sign define CS' . vFlagNum . ' text='. vFlagNum .' texthl=ErrorMsg'
s1gns "exe 'sign place ' . b:Sign_num . ' line=' . ln . ' name=CS'. FlagNum . ' buffer=' . winbufnr(0)
exe 'sign place ' . vFlagNum . ' line=' . vLn . ' name=CS'. vFlagNum . ' file=' . vFileNames1gns
" record the last index.s1gns let s:myIndex = s:Sign_num
let s:Sign_num = s:Sign_num + 1s1gns let s:mylist = s:mylist + vFlagNum,vLn,vFileName
endif s1gns "echo s:mylist
"unlet newItem
endfun

" ---------------------------------------------------------------------
" Remove one sign
fun! s:Remove_sign(aIndex)s1gns
silent! exe 'sign unplace ' .s:mylist[a:aIndex][0] . ' file=' . s:mylist[a:aIndex][2]s1gns "echo 'sign unplace ' .s:mylist[a:aIndex][0] . ' file=' . s:mylist[a:aIndex][2]
s1gns " record the before item
let s:tmplist = s:mylist[a:aIndex - 1]s1gns
let i = remove(s:mylist, a:aIndex)s1gns
" record the current index.s1gns let s:myIndex = s:Check_list(s:tmplist)
let s:deleteFlag = 1s1gns "echo s:mylist
endfun

" ---------------------------------------------------------------------
" Remove all signs
fun! Remove_all_signs()s1gns silent! exe 'sign unplace *'
if len(s:mylist) > 1 s1gns let i = remove(s:mylist, 1, -1)
let s:Sign_num = 1s1gns endif
"echo s:mylist
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)s1gns let vResult = -1
let index = 0s1gns
for item in s:mylists1gns "echo item[1] . "-" . a:aItem[1] . "=" . item[2] . "-" . a:aItem[2]
if ((item[1] ==? a:aItem[1]) && (item[2] ==? a:aItem[2]))s1gns return index
endifs1gns let index = index + 1
endfors1gns
return vResult
endfun

" ---------------------------------------------------------------------
" Goto prev sign:
fun! Goto_prev_sign()s1gns if len(s:mylist) > 1
if s:deleteFlag == 0 s1gns let s:myIndex = s:myIndex - 1
elses1gns let s:deleteFlag = 0
endifs1gns
if s:myIndex <= 0s1gns let s:myIndex = len(s:mylist) - 1
endifs1gns silent! exe 'sign jump '. s:mylist[s:myIndex][0] . ' file='. s:mylist[s:myIndex][2]
"echo 'sign jump '. s:mylist[s:myIndex][0] . ' file='. s:mylist[s:myIndex][2]s1gns endif
endfun

" ---------------------------------------------------------------------
" Goto next sign:
fun! Goto_next_sign()s1gns if len(s:mylist) > 1
let s:myIndex = s:myIndex + 1s1gns if ((s:myIndex >= len(s:mylist)) || (s:myIndex == 1))
let s:myIndex = 1s1gns endif
silent! exe 'sign jump '. s:mylist[s:myIndex][0] . ' file='. s:mylist[s:myIndex][2]s1gns "echo 'sign jump '. s:mylist[s:myIndex][0] . ' file='. s:mylist[s:myIndex][2]
endif
endfun

" ---------------------------------------------------------------------