用户讨论:Corey

来自Ubuntu中文
Corey留言 | 贡献2008年4月11日 (五) 15:15的版本
跳到导航跳到搜索

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

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

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

vim marks

let s:remarkItem = ["REMARK","SEARCH","FLAG"]

" remark
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]
"echo 'sign define CS' . s:remarkItem[0] . ' text='. s:remarkItem[0] .' texthl=ErrorMsg'
silent! exe 'sign define CS' . s:remarkItem[0] . ' text='. s:remarkItem[0] .' texthl=ErrorMsg'
"echo 'sign place ' . s:remarkItem[0] . ' line=' . s:remarkItem[1] . ' name=CS' . s:remarkItem[0] . ' file=' . s:remarkItem[2]
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(aSignID, aFileName)
let bufferList = s:GetBufferList()
"echo bufferList
let bufferExits = s:Seach_file(a:aFileName, bufferList)

if bufferExits > 0
silent! exe 'tabn ' . bufferExits
silent! exe 'sign jump '. a:aSignID[0] . ' file='. a:aFileName
else
call s:Open_file(a:aFileName)

silent! exe 'sign place ' . a:aSignID[0] . ' line=' . a:aSignID[1] . ' name=CS'. a:aSignID[0] . ' file=' . a:aSignID[2]

silent! exe 'sign jump '. a:aSignID[0] . ' file='. a:aFileName
endif

endfun
" ---------------------------------------------------------------------
" get buffer list
fun! s:GetBufferList()

let vResult = [["0","[ * THE <?> HEAD * ]"]]
let i = 0

while i < tabpagenr('$')

"exe 'tabn ' . i + 1
if i == 0
silent! exe 'tabfirst'
else
silent! exe 'tabnext'
endif
let bufname = expand("%:p")
let vResult = vResult + i + 1, bufname
let i = i + 1
endwhile

return vResult
endfun

" ---------------------------------------------------------------------
" open file
fun! s:Open_file(aFileName)
if filereadable(a:aFileName)
"call s:Flash_signs()
if tabpagenr('$') > 1
silent! exe 'tabnew '. a:aFileName
silent! exe 'tabn ' . tabpagenr('$')
else
silent! exe 'e '. a:aFileName
endif
endif
endfun
" ---------------------------------------------------------------------
" search file
" find the file, return the position; else return -1
fun! s:Seach_file(aFileName, aBufferList)

let vResult = -1

if len(a:aBufferList) > 1
if s:win32Flag == 1
for item in a:aBufferList
" file name is ignoring case
if (item[1] ==? a:aFileName)
return item[0]
endif
endfor
else
for item in a:aBufferList
" file name is matching case
if (item[1] ==# a:aFileName)
return item[0]
endif
endfor
endif
endif
return vResult
endfun
" ---------------------------------------------------------------------