diff --git a/plugin/gundo.vim b/plugin/gundo.vim index c143f63..0308037 100644 --- a/plugin/gundo.vim +++ b/plugin/gundo.vim @@ -22,38 +22,23 @@ endif "}}} "{{{ Movement Mappings -function! s:GundoMoveUp() +function! s:GundoMove(direction) let start_line = getline('.') - if line('.') - 2 <= 4 + + if stridx(start_line, '[') == -1 + let distance = 1 + else + let distance = 2 + endif + + let target_n = line('.') + (distance * a:direction) + + if target_n <= 4 call cursor(5, 0) - elseif stridx(start_line, '[') == -1 - call cursor(line('.') - 1, 0) - else - call cursor(line('.') - 2, 0) - endif - - let line = getline('.') - let idx1 = stridx(line, '@') - let idx2 = stridx(line, 'o') - if idx1 != -1 - call cursor(0, idx1 + 1) - else - call cursor(0, idx2 + 1) - endif - - let target_line = matchstr(getline("."), '\v\[[0-9]+\]') - let target_num = matchstr(target_line, '\v[0-9]+') - call s:GundoRenderPreview(target_num) -endfunction - -function! s:GundoMoveDown() - let start_line = getline('.') - if line('.') + 2 >= line('$') + elseif target_n >= line('$') call cursor(line('$') - 1, 0) - elseif stridx(start_line, '[') == -1 - call cursor(line('.') + 1, 0) else - call cursor(line('.') + 2, 0) + call cursor(target_n, 0) endif let line = getline('.') @@ -88,8 +73,10 @@ function! s:GundoOpenBuffer() wincmd H call s:GundoResizeBuffers(winnr()) nnoremap