From 39983fbd30c7d67b35ff317aaef0be5c1ba558ca Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Mon, 30 Jul 2018 10:06:08 -0700 Subject: [PATCH] Add refresh command Stores GV's options, closes tab, re-runs GV. Doesn't maintain current diff window, but does maintain current line position. Seems like a good trade-off for a simpler solution. Mapped to 'r' like fugitive's :Gstatus. (Instead of 'u' like gitv.) Implemented as a plug because I personally prefer C-l for refresh-like actions (and have already mapped r to cycle refs like gitv). Store restore variables in buffer instead of tab because if you :GV and then :wincmd T, then the t: variables disappear. I can't think of a way we'd lose the buffer. We create the new buffer with the old buffer's arguments, so they're still pointing to the right ones. --- README.md | 1 + plugin/gv.vim | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 10e97a4..1fcb202 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ selected lines. - `gb` for `:GBrowse` - `]]` and `[[` to move between commits - `.` to start command-line with `:Git [CURSOR] SHA` à la fugitive +- `r` to refresh git state - `q` or `gq` to close Customization diff --git a/plugin/gv.vim b/plugin/gv.vim index 8e91611..9de8d4b 100644 --- a/plugin/gv.vim +++ b/plugin/gv.vim @@ -126,6 +126,8 @@ function! s:dot() endfunction function! s:maps() + nnoremap (gv-refresh) :call refresh() + nnoremap q :$wincmd w close nnoremap gq :$wincmd w close nnoremap gb :call gbrowse() @@ -317,6 +319,13 @@ function! s:gv(bang, visual, line1, line2, args) abort call s:list(log_opts) call FugitiveDetect(@#) endif + let b:gv_opts = { + \ 'bang' : a:bang, + \ 'visual' : a:visual, + \ 'line1' : a:line1, + \ 'line2' : a:line2, + \ 'args' : a:args, + \ } catch return s:warn(v:exception) finally @@ -326,4 +335,17 @@ function! s:gv(bang, visual, line1, line2, args) abort endtry endfunction +function! s:refresh() abort + let lazyredraw_bak = &lazyredraw + let &lazyredraw = 1 + + let win = winsaveview() + let old_tab = tabpagenr() + call s:gv(b:gv_opts.bang, b:gv_opts.visual, b:gv_opts.line1, b:gv_opts.line2, b:gv_opts.args) + exec 'tabclose '. old_tab + call winrestview(win) + + let &lazyredraw = lazyredraw_bak +endfunction + command! -bang -nargs=* -range=0 -complete=customlist,fugitive#CompleteObject GV call s:gv(0, , , , )