Redo Blame command for vim
This commit is contained in:
parent
00b4e918c0
commit
c01fecb8b2
1 changed files with 25 additions and 39 deletions
26
git.vim
26
git.vim
|
@ -1,3 +1,4 @@
|
|||
" vim: set noexpandtab :miv "
|
||||
" ┌─────────────────┐ "
|
||||
" └─┬─┬───┬─┬───┬─┬─┘ "
|
||||
" │ │ │ │ │ │ "
|
||||
|
@ -164,28 +165,13 @@ function! s:git_diff(...)
|
|||
end
|
||||
endfun
|
||||
|
||||
function! s:git_blame()
|
||||
let l:name = expand('%')
|
||||
let l:line = getpos('.')[1]
|
||||
let l:char = getpos('.')[2]+59
|
||||
let l:type = &filetype
|
||||
enew
|
||||
set modifiable
|
||||
let &filetype = l:type
|
||||
set buftype=nofile
|
||||
set bufhidden=delete
|
||||
set nowrap
|
||||
silent exec "file Blame: ".l:name
|
||||
keepjumps exec 'r !git blame '.l:name
|
||||
keepjumps 0,0del "
|
||||
set nomodifiable
|
||||
keepjumps call setpos('.', [0, l:line, l:char, 0])
|
||||
function! s:git_blame(first, last)
|
||||
let l:input = system('git blame '.expand('%').' --line-porcelain -L '.a:first.','.a:last)
|
||||
let l:data = map(split(l:input, '\ze\x\{40} \d\+ \d\+'), {idx, elem -> split(elem, '\n')})
|
||||
return map(l:data, {idx, ary -> ary[1][match(ary[1], '\s\+\zs'):]})
|
||||
endfun
|
||||
|
||||
command! Blame try
|
||||
\| call s:gitroot() | call <sid>git_blame()
|
||||
\| catch | echo 'Not a git repo!'
|
||||
\| endtry
|
||||
command! -range Blame echom join(uniq(sort(<sid>git_blame(<line1>, <line2>))), ', ')
|
||||
command! GitNext try
|
||||
\| call s:gitroot() | call <sid>git_next() | call s:git_info()
|
||||
\| catch | echo 'Not a git repo!'
|
||||
|
|
Loading…
Reference in a new issue