Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
git blame for current line
" -- 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