用户讨论:Corey

来自Ubuntu中文
Corey留言 | 贡献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

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