Skip to content

Commit f0644fe

Browse files
committed
GitBlame
1 parent d38f090 commit f0644fe

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

plugin/git.vim

+29
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,34 @@ function! GitCatFile(file)
173173
call <SID>OpenGitBuffer(git_output)
174174
endfunction
175175

176+
" Show revision and author for each line.
177+
function! GitBlame()
178+
let git_output = s:SystemGit('blame -- ' . expand('%'))
179+
if !strlen(git_output)
180+
echo "No output from git command"
181+
return
182+
endif
183+
184+
setlocal noscrollbind
185+
186+
" :/
187+
let git_command_edit_save = g:git_command_edit
188+
let g:git_command_edit = 'leftabove vnew'
189+
call <SID>OpenGitBuffer(git_output)
190+
let g:git_command_edit = git_command_edit_save
191+
192+
setlocal modifiable
193+
silent %s/\d\d\d\d\zs \+\d\+).*//
194+
vertical resize 20
195+
setlocal nomodifiable
196+
setlocal nowrap scrollbind
197+
198+
wincmd p
199+
setlocal nowrap scrollbind
200+
201+
syncbind
202+
endfunction
203+
176204
function! GitDoCommand(args)
177205
let git_output = s:SystemGit(a:args)
178206
let git_output = substitute(git_output, '\n*$', '', '')
@@ -265,6 +293,7 @@ command! -nargs=? GitAdd call GitAdd(<q-args>)
265293
command! -nargs=* GitLog call GitLog(<q-args>)
266294
command! -nargs=* GitCommit call GitCommit(<q-args>)
267295
command! -nargs=1 GitCatFile call GitCatFile(<q-args>)
296+
command! GitBlame call GitBlame()
268297
command! -nargs=+ Git call GitDoCommand(<q-args>)
269298
command! GitVimDiffMerge call GitVimDiffMerge()
270299
command! GitVimDiffMergeDone call GitVimDiffMergeDone()

0 commit comments

Comments
 (0)