Hi guys, I use vim to edit my PHP project, sometimes i need to jump to
the declaration of  functions and variables, or jump to many marked
positions. Maybe only in one file, i forward to many position
(anchor),  is there any plugin, or any usefull vim script to easy
forward/backword to the positions?  If it support to jump to different
file positions, that's good enough,

The feature i want just like in Zend Studio, you can use <Alt-,>,
<Alt-.> to forward/backward positions.

I have tried cscope, ctags, but these still not work perfectly, and
they dont save marks.  Maybe i need to save the specific positions
info, so i wrote a script, and it can jump from one file now.  Below
is part of my script, any errors,  pls correct me:), and if you know
any plugin, pls tell me, thanks.


""""""""""""""""""""""""""""""""""""
" Mark Functions Start
""""""""""""""""""""""""""""""""""""
let g:globalFileSpace  = {}
let g:globalMarkList =
['a','b','c','d','e','f','g','h','i','j','k','l','n','o','p','q','r','s','t','u','v','w','x','y','z']


function! ResetGlobalFileMarkIndex()
    try
        let g:globalFileSpace[expand("%:p")]['index'] = 0
        let g:globalFileSpace[expand("%:p")]['indexUsed'] = 0
        exec ":delmarks a-z"
    catch /.*/
        call InitFileMarkIndex()
        let g:globalFileSpace[expand("%:p")]['index'] = 0
        let g:globalFileSpace[expand("%:p")]['indexUsed'] = 0
        exec ":delmarks a-z"
    endtry
endfunction

function! ShowFileMarkInfo()
    try
      echo "index = " . g:globalFileSpace[expand("%:p")]['index']
      echo "indexUsed = " . g:globalFileSpace[expand("%:p")]
['indexUsed']
    catch /.*/
        echo "Not set global index"
    endtry
endfunction

function! InitGlobalFileSpace()
    if !has_key(g:globalFileSpace,expand("%:p"))
        let g:globalFileSpace[expand("%:p")] = {}
    end
endfunction

function! InitFileMarkIndex()
    if !has_key(g:globalFileMarks,expand("%:p"))
        call InitGlobalFileSpace()
    end
    if !has_key(g:globalFileSpace[expand("%:p")],'index')
        let g:globalFileSpace[expand("%:p")]['index'] = 0
    end
    if !has_key(g:globalFileSpace[expand("%:p")],'indexUsed')
        let g:globalFileSpace[expand("%:p")]['indexUsed'] = 0
    end
endfunction

function! GetIndexMark(...)
    if !exists("a:1")
        echo "Error: GetIndexMark need param1"
        return 0
    end
    let index = a:1
    if index<0 || index>24
        return ''
    end
    try
        let mark = g:globalMarkList[index]
        return mark
    catch /.*/
        echo "Error: GetIndexMark() index Mark Not found."
        return ''
    endtry
endfunction

function! LoopGetIndexMark(...)
    "@parm1 index
    "@parm2 forward
    let index = a:1
    if exists("a:2")
        let forword = a:2
    else
        let forword = 1
    end
    if forword
        let index = index + 1
    else
        let index = index - 1
    end
    if index>24
        let index = 0
    end
    if index<0
        let index = 24
    end
    let mark = get(g:globalMarkList,index,'')
    if strlen(mark)
        return [mark,index]
    else
        return ['','']
    end
endfunction

function! GetFileMarkIndex(...)
    try
        let index = g:globalFileSpace[expand("%:p")]['index']
    catch /.*/
        call InitFileMarkIndex()
        let index = g:globalFileSpace[expand("%:p")]['index']
    endtry
    return index
endfunction

function! SetFileMarkIndex(...)
    if !exists("a:1")
        echo "error in setting used index."
        return
    end
    let index = a:1
    try
        let g:globalFileSpace[expand("%:p")]['index'] = index
    catch /.*/
        call InitFileMarkIndex()
        let g:globalFileSpace[expand("%:p")]['index'] = index
    endtry
    return 1
endfunction

function! SetFileMarkUsedIndex(...)
    if !exists("a:1")
        echo "error in setting used index."
        return
    end
    let index = a:1
    try
        let index = a:1
        let g:globalFileSpace[expand("%:p")]['indexUsed'] = index
    catch /.*/
        call InitFileMarkIndex()
        let g:globalFileSpace[expand("%:p")]['indexUsed'] = index
    endtry
    return 1
endfunction

function! GetFileMarkUsedIndex(...)
    try
        let index = g:globalFileSpace[expand("%:p")]['indexUsed']
    catch /.*/
        call InitFileMarkIndex()
        let index = g:globalFileSpace[expand("%:p")]['indexUsed']
    endtry
    return index
endfunction

function! GetFileCurrentMark()
    let index = GetFileMarkIndex()
    return GetIndexMark(index)
endfunction

function! MarkChar(...)
    if !exists("a:1")
        echo "Error param in Mark()
        return
    end
    let char = a:1
    exec "norm m" . char
endfunction

function! GetOffsetMark(...)
    "@param1: offset
    "@parma2: start
    if !exists("a:1")
        echo "Error: GotoIndexMark() need param1 offset"
        return
    end
    let offset = a:1
    if exists("a:2")
        let start = a:2
    else
        let start = GetFileMarkIndex()
    end
    let index = start + offset
    let mark = GetIndexMark(index)
    let mycount=1
    while !IsMarkExists(mark) && mycount<30
        let ret = LoopGetIndexMark(index,(offset>0))
        let mark = ret[0]
        let index = ret[1]
        let mycount = mycount + 1
    endwhile
    if IsMarkExists(mark)
        call SetFileMarkIndex(index)
        call JumpToMark( mark )
    else
        echo "Cannot find suggest mark: " . mark
    end
    return
endfunction

function! IsMarkExists(...)
    let mark = a:1
    if strlen(mark)<1
        return 0
    end
    if getpos("'".mark) == [0,0,0,0]
        return 0
    else
        return 1
    end
endfunction


function! GotoNextMark()
    call GetOffsetMark(1)
endfunction

function! GotoPrevMark()
    call GetOffsetMark(-1)
endfunction


function! JumpToMark(...)
    if !exists("a:1")
        return
    end
    let mark = a:1
    try
        exec "norm '" . a:1
        echo "Mark found: " . mark
    catch /.*/
        echo "Mark not found: " . mark
    endtry
endfunction

function! MarkInc()
    try
        let indexUsed = GetFileMarkUsedIndex()
        let index = indexUsed
    catch /.*/
        call InitFileMarkIndex()
        let indexUsed = GetFileMarkUsedIndex()
        let index = indexUsed
    endtry
    if index == 24
        let index = 0
        let markChar = GetIndexMark( index )
    else
        let ret = LoopGetIndexMark(index)
        let index = ret[1]
        let markChar = ret[0]
    end
    if strlen(markChar)
        call SetFileMarkUsedIndex(index)
        call SetFileMarkIndex(index)
        call MarkChar(markChar)
    else
        echo "Error to get inc mark char"
    end
endfunction

""""""""""""""""""""""""""""""""""""
" Mark Functions End
""""""""""""""""""""""""""""""""""""

" To bind forward/backward to <Alt-.>, <Alt-,>
nmap <M-.> :call GotoNextMark()<CR>
nmap <M-,> :call GotoPrevMark()<CR>

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to