diff options
author | Teddy Wing | 2018-03-07 20:52:34 +0100 |
---|---|---|
committer | Teddy Wing | 2018-03-07 20:52:34 +0100 |
commit | 26d6b13bc20582b09df7ee40c7d0f2c2580d19e2 (patch) | |
tree | 9391cb41960015488868e4e3ae4a55927e2e6a5c | |
parent | 319a253ef10513a53c08dab57ab677ae22621a9f (diff) | |
download | dotvim-26d6b13bc20582b09df7ee40c7d0f2c2580d19e2.tar.bz2 |
git-blamer: Align cursor lines of buffer and GitBlamer window
Take the mechanism that Fugitive.vim uses:
https://github.com/tpope/vim-fugitive/blob/f3ccb0c12ee4985b8808f83059830a24cc92821c/plugin/fugitive.vim#L2048-L2064
This positions the cursor lines on the same horizontal line so that
blame information can be read on the same line as the code it
corresponds to.
Not sure, but it doesn't seem to work exactly right on one of my
machines, but did appear to work correctly on another. Could just be the
fault of 'wrap' though.
-rw-r--r-- | bundle/git-blamer/autoload/git_blamer.vim | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/bundle/git-blamer/autoload/git_blamer.vim b/bundle/git-blamer/autoload/git_blamer.vim index c88f05a..40ffddb 100644 --- a/bundle/git-blamer/autoload/git_blamer.vim +++ b/bundle/git-blamer/autoload/git_blamer.vim @@ -3,6 +3,7 @@ " https://github.com/r00k/dotfiles/blob/7874508b825fd754e4ec3259da65f324ab96c8ea/vimrc#L74 function! git_blamer#Blame() + let l:top_line = line('w0') + &scrolloff let l:line_number = line('.') let l:buffer_name = shellescape(bufname('%')) let l:buffer_number = bufnr('%') @@ -11,8 +12,6 @@ function! git_blamer#Blame() " Open new window leftabove vnew - setlocal noswapfile nowrap nolist nobuflisted buftype=nofile bufhidden=wipe - setlocal scrollbind cursorbind let b:git_blamer_restore = 'call setbufvar(' . l:buffer_number . ', "&scrollbind", 0) | \ call setbufvar(' . l:buffer_number . ', "&cursorbind", 0)' @@ -26,8 +25,13 @@ function! git_blamer#Blame() setlocal nomodified nomodifiable " Move cursor to position in starting file + execute l:top_line + normal! zt call setpos('.', [0, l:line_number, 0, 0]) + setlocal noswapfile nowrap nolist nobuflisted buftype=nofile bufhidden=wipe + setlocal scrollbind cursorbind + " Restore starting file's scrollbind on exit autocmd BufWinLeave <buffer> execute b:git_blamer_restore endfunction |