diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 53ad9dd..d965716 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -818,31 +818,7 @@ function! s:buffer_expand(rev) dict abort \ '\.\@<=/$','') endfunction -function! s:buffer_up(...) dict abort - let rev = self.rev() - let c = a:0 ? a:1 : 1 - while c - if rev =~# '^[/:]$' - let rev = 'HEAD' - elseif rev =~# '^:' - let rev = ':' - elseif rev =~# '^refs/[^^~:]*$\|^[^^~:]*HEAD$' - let rev .= '^{}' - elseif rev =~# '^/\|:.*/' - let rev = s:sub(rev, '.*\zs/.*', '') - elseif rev =~# ':.' - let rev = matchstr(rev, '^[^:]*:') - elseif rev =~# ':$' - let rev = rev[0:-2] - else - return rev.'~'.c - endif - let c -= 1 - endwhile - return rev -endfunction - -call s:add_methods('buffer',['getvar','getline','repo','type','spec','name','commit','path','relative','rev','expand','up']) +call s:add_methods('buffer',['getvar','getline','repo','type','spec','name','commit','path','relative','rev','expand']) " Section: Git @@ -2996,13 +2972,37 @@ function! s:ContainingCommit() abort endif endfunction +function! s:NavigateUp(count) dict abort + let rev = self.rev() + let c = a:count + while c + if rev =~# '^[/:]$' + let rev = 'HEAD' + elseif rev =~# '^:' + let rev = ':' + elseif rev =~# '^refs/[^^~:]*$\|^[^^~:]*HEAD$' + let rev .= '^{}' + elseif rev =~# '^/\|:.*/' + let rev = s:sub(rev, '.*\zs/.*', '') + elseif rev =~# ':.' + let rev = matchstr(rev, '^[^:]*:') + elseif rev =~# ':$' + let rev = rev[0:-2] + else + return rev.'~'.c + endif + let c -= 1 + endwhile + return rev +endfunction + function! fugitive#MapJumps(...) abort nnoremap :exe GF("edit") if !&modifiable nnoremap o :exe GF("split") nnoremap S :exe GF("vsplit") nnoremap O :exe GF("tabedit") - nnoremap - :exe Edit('edit',0,'',buffer().up(v:count1)) if fugitive#buffer().type('tree')call search('^'.escape(expand('#:t'),'.*[]~\').'/\=$','wc')endif + nnoremap - :exe Edit('edit',0,'',NavigateUp(v:count1)) if fugitive#buffer().type('tree')call search('^'.escape(expand('#:t'),'.*[]~\').'/\=$','wc')endif nnoremap P :exe Edit('edit',0,'',ContainingCommit().'^'.v:count1.buffer().relative(':')) nnoremap ~ :exe Edit('edit',0,'',ContainingCommit().'~'.v:count1.buffer().relative(':')) nnoremap C :exe Edit('edit',0,'',ContainingCommit())