Last active
February 5, 2019 19:30
-
-
Save ryanpetrello/8397a8b71c1406112482bd008d70c1b6 to your computer and use it in GitHub Desktop.
git blame for current line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" -- git blame for current file | |
function! GitBlame() | |
let sha = matchstr(system('git --no-pager blame '.expand('%').' -L '.line('.').',+1'), '^\^*\zs\S\+') | |
let command = join(map(split('git show '.sha), 'expand(v:val)')) | |
let winnr = bufwinnr('git.blame') | |
silent! execute winnr < 0 ? 'botright new ' . 'git.blame' : winnr . 'wincmd w' | |
setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile nowrap number filetype=diff | |
silent! execute 'silent %!'. command | |
silent! execute 'nnoremap <silent> <buffer> q :q! <CR>' | |
endfunction | |
map <leader>b :call GitBlame()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment