Skip to content

Instantly share code, notes, and snippets.

@ryanpetrello
Last active February 5, 2019 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanpetrello/8397a8b71c1406112482bd008d70c1b6 to your computer and use it in GitHub Desktop.
Save ryanpetrello/8397a8b71c1406112482bd008d70c1b6 to your computer and use it in GitHub Desktop.
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