用户讨论:Corey:修订间差异
小无编辑摘要 |
小无编辑摘要 |
||
第7行: | 第7行: | ||
[[Image:Vim marks.PNG|vim marks]] | [[Image:Vim marks.PNG|vim marks]] | ||
<br> | let s:remarkItem = ["REMARK","SEARCH","FLAG"]<br> | ||
" remark<br>fun! Move_sign() | |||
let s:tempItem = ["","",""]<br> let vRLn = "".line(".")<br> let vRFileName = expand("%:p") | let s:tempItem = ["","",""]<br> let vRLn = "".line(".")<br> let vRFileName = expand("%:p") | ||
第15行: | 第15行: | ||
let s:tempItem[1] = vRLn<br> let s:tempItem[2] = vRFileName<br> "echo s:tempItem <br> let vRIndex = s:Check_list(s:tempItem) | 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> "echo 'sign define CS' . s:remarkItem[0] . ' text='. s:remarkItem[0] .' texthl=ErrorMsg'<br> silent! exe 'sign define CS' . s:remarkItem[0] . ' text='. s:remarkItem[0] .' texthl=ErrorMsg'<br> "echo 'sign place ' . s:remarkItem[0] . ' line=' . s:remarkItem[1] . ' name=CS' . s:remarkItem[0] . ' file=' . s:remarkItem[2]<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> | 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> "echo 'sign define CS' . s:remarkItem[0] . ' text='. s:remarkItem[0] .' texthl=ErrorMsg'<br> silent! exe 'sign define CS' . s:remarkItem[0] . ' text='. s:remarkItem[0] .' texthl=ErrorMsg'<br> "echo 'sign place ' . s:remarkItem[0] . ' line=' . s:remarkItem[1] . ' name=CS' . s:remarkItem[0] . ' file=' . s:remarkItem[2]<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> " -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*<br>" all of them used for the jump.<br>fun! s:Sign_jump(aSignID, aFileName)<br> let bufferList = s:GetBufferList()<br> "echo bufferList<br> let bufferExits = s:Seach_file(a:aFileName, bufferList) | ||
if bufferExits > 0<br> silent! exe 'tabn ' . bufferExits<br> silent! exe 'sign jump '. a:aSignID[0] . ' file='. a:aFileName<br> else<br> 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<br> endif | |||
endfun<br>" ---------------------------------------------------------------------<br>" get buffer list <br>fun! s:GetBufferList()<br> <br> let vResult = [["0","[ * THE <?> HEAD * ]"]]<br> let i = 0 | |||
while i < tabpagenr('$') | |||
return 0<br> | "exe 'tabn ' . i + 1<br> if i == 0 <br> silent! exe 'tabfirst'<br> else<br> silent! exe 'tabnext'<br> endif<br> let bufname = expand("%:p")<br> let vResult = vResult + [[i + 1, bufname]]<br> let i = i + 1<br> endwhile <br> <br> return vResult<br>endfun | ||
" ---------------------------------------------------------------------<br>" open file<br>fun! s:Open_file(aFileName)<br> if filereadable(a:aFileName)<br> "call s:Flash_signs()<br> if tabpagenr('$') > 1 <br> silent! exe 'tabnew '. a:aFileName<br> silent! exe 'tabn ' . tabpagenr('$')<br> else<br> silent! exe 'e '. a:aFileName<br> endif<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 | |||
if len(a:aBufferList) > 1 <br> if s:win32Flag == 1<br> for item in a:aBufferList<br> " file name is ignoring case<br> if (item[1] ==? a:aFileName)<br> return item[0]<br> endif<br> endfor<br> else<br> for item in a:aBufferList<br> " file name is matching case<br> if (item[1] ==# a:aFileName)<br> return item[0]<br> endif<br> endfor<br> endif <br> endif<br> return vResult<br>endfun<br>" ---------------------------------------------------------------------<br><br> |
2008年4月11日 (五) 15:15的版本
喜欢使用ubuntu和vim,但是都不是很了解,都在慢慢学!
最近写的一个gvim的marks脚本。方便自己方便大家!
链接 http://www.vim.org/scripts/script.php?script_id=2194
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
" ---------------------------------------------------------------------