From 9619055cfd5d049b3dc67fcdd3cc2f263d72affc Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sat, 7 Apr 2012 16:14:51 -0400 Subject: [PATCH] Map - to go up a directory --- doc/fugitive.txt | 3 +++ plugin/fugitive.vim | 27 ++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/doc/fugitive.txt b/doc/fugitive.txt index 3d95f65..d1514ff 100644 --- a/doc/fugitive.txt +++ b/doc/fugitive.txt @@ -235,6 +235,9 @@ o Jump to the revision under the cursor in a new split. *fugitive-O* O Jump to the revision under the cursor in a new tab. + *fugitive--* +- Go to the tree containing the current tree or blob. + *fugitive-~* ~ Go to the current file in the [count]th first ancestor. diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 1c05877..16cb6ab 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -537,7 +537,31 @@ function! s:buffer_containing_commit() dict abort endif endfunction -call s:add_methods('buffer',['getvar','setvar','getline','repo','type','spec','name','commit','path','rev','sha1','expand','containing_commit']) +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 =~# '^[^^~:]\+$' + 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','setvar','getline','repo','type','spec','name','commit','path','rev','sha1','expand','containing_commit','up']) " }}}1 " Git {{{1 @@ -2149,6 +2173,7 @@ function! s:JumpInit() abort if !&modifiable nnoremap o :exe GF("split") nnoremap O :exe GF("tabedit") + nnoremap - :exe Edit('edit',0,buffer().up(v:count1)) nnoremap P :exe Edit('edit',0,buffer().commit().'^'.v:count1.buffer().path(':')) nnoremap ~ :exe Edit('edit',0,buffer().commit().'~'.v:count1.buffer().path(':')) nnoremap C :exe Edit('edit',0,buffer().containing_commit())