From 8cf3d94a3adff7ee9468a1c396d0ae1ecfce9c91 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 7 Oct 2015 00:03:06 -0400 Subject: [PATCH] Support gf in git filetypes Closes https://github.com/tpope/vim-fugitive/issues/697 --- plugin/fugitive.vim | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index b5d2398..af4d088 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -2696,6 +2696,10 @@ augroup fugitive_files \ if exists('b:git_dir') | \ call s:JumpInit() | \ endif + autocmd FileType git,gitcommit,gitrebase + \ if exists('b:git_dir') | + \ call s:GFInit() | + \ endif augroup END " Section: Temp files @@ -2719,7 +2723,18 @@ augroup END " Section: Go to file -function! s:JumpInit() abort +nnoremap : :=v:count ? v:count : '' +function! s:GFInit(...) abort + cnoremap fugitive#cfile() + if !exists('g:fugitive_no_maps') && empty(mapcheck('gf', 'n')) + nmap gf :find + nmap f :sfind + nmap :sfind + nmap gf :tabfind + endif +endfunction + +function! s:JumpInit(...) abort nnoremap :exe GF("edit") if !&modifiable nnoremap o :exe GF("split") @@ -2928,6 +2943,17 @@ function! s:GF(mode) abort endif endfunction +function! fugitive#cfile() abort + let pre = '' + let results = s:cfile() + if empty(results) + return expand('') + elseif len(results) > 1 + let pre = '+' . join(map(results[1:-1], 'escape(v:val, " ")'), '\|') . ' ' + endif + return pre . s:fnameescape(fugitive#repo().translate(results[0])) +endfunction + " Section: Statusline function! s:repo_head_ref() dict abort