diff options
author | Teddy Wing | 2015-07-23 03:03:19 -0400 |
---|---|---|
committer | Teddy Wing | 2015-07-23 03:03:19 -0400 |
commit | 2157680c7fd1aebd4aeae2ba102c30ec0349a574 (patch) | |
tree | 9fa4a9dcb77750a943183b4ce21ae164af9564aa /bundle/git-blamer | |
parent | d13db2d5906ab17036837adef94e5df2b559febd (diff) | |
download | dotvim-2157680c7fd1aebd4aeae2ba102c30ec0349a574.tar.bz2 |
Add git-blamer plugin
Create a plugin that runs a `git blame` and opens the result in a new
vertical split. This one builds on
a43d3caaea3682f58aee6dc295e48cca415067c5 but improves it by adding some
extra niceties including moving to the line the cursor was on in the
original file, setting appropriate flags so that the split doesn't
appear in the buffer list and becomes non-modifiable, and setting cursor
and scroll binding so that the buffers scroll together. An `autocmd`
resets the original buffer to `noscrollbind` and `nocursorbind`.
Diffstat (limited to 'bundle/git-blamer')
-rw-r--r-- | bundle/git-blamer/autoload/git_blamer.vim | 28 | ||||
-rw-r--r-- | bundle/git-blamer/plugin/git_blamer.vim | 1 |
2 files changed, 29 insertions, 0 deletions
diff --git a/bundle/git-blamer/autoload/git_blamer.vim b/bundle/git-blamer/autoload/git_blamer.vim new file mode 100644 index 0000000..cd6d83f --- /dev/null +++ b/bundle/git-blamer/autoload/git_blamer.vim @@ -0,0 +1,28 @@ +function! git_blamer#Blame() + let l:line_number = line('.') + let l:buffer_name = shellescape(bufname('%')) + let l:window_number = winnr() + + setlocal scrollbind cursorbind + let t:git_blamer_restore = 'call setwinvar(' . l:window_number . ', "&scrollbind", 0) | + \ call setwinvar(' . l:window_number . ', "&cursorbind", 0)' + + " Open new window + vnew + setlocal noswapfile nowrap nolist nobuflisted buftype=nofile bufhidden=wipe + setlocal scrollbind cursorbind + + " Read in `git blame` output + execute 'read !git blame ' . l:buffer_name + + " Delete empty first line + 1 delete + + setlocal nomodified nomodifiable + + " Move cursor to position in starting file + call setpos('.', [0, l:line_number, 0, 0]) + + " Restore starting file's scrollbind on exit + autocmd BufWinLeave <buffer> execute t:git_blamer_restore +endfunction diff --git a/bundle/git-blamer/plugin/git_blamer.vim b/bundle/git-blamer/plugin/git_blamer.vim new file mode 100644 index 0000000..52197da --- /dev/null +++ b/bundle/git-blamer/plugin/git_blamer.vim @@ -0,0 +1 @@ +command! GitBlamer :call git_blamer#Blame() |