From a26423b0bb8b7b5f0dcb5544de148acfefefe7ff Mon Sep 17 00:00:00 2001 From: Bertrand Sim Date: Mon, 7 Jun 2021 17:13:10 +0800 Subject: [PATCH 1/2] refresh GV buffer with r store the git_log_cmd as a buffer-local variable. `b:git_log_cmd` can then be used to refresh, by passing this variable to s:fill(). --- plugin/gv.vim | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plugin/gv.vim b/plugin/gv.vim index b59a12d..a946755 100644 --- a/plugin/gv.vim +++ b/plugin/gv.vim @@ -167,6 +167,7 @@ endfunction function! s:maps() nnoremap q :$wincmd w close nnoremap gq :$wincmd w close + nnoremap r :call refresh() nnoremap gb :call gbrowse() nnoremap :call open(0) nnoremap o :call open(0) @@ -248,13 +249,13 @@ endfunction function! s:list(fugitive_repo, log_opts) let default_opts = ['--color=never', '--date=short', '--format=%cd %h%d %s (%an)'] let git_args = ['log'] + default_opts + a:log_opts - let git_log_cmd = FugitiveShellCommand(git_args, a:fugitive_repo) + let b:git_log_cmd = FugitiveShellCommand(git_args, a:fugitive_repo) let repo_short_name = fnamemodify(substitute(a:fugitive_repo.dir(), '[\\/]\.git[\\/]\?$', '', ''), ':t') let bufname = repo_short_name.' '.join(a:log_opts) silent exe (bufexists(bufname) ? 'buffer' : 'file') fnameescape(bufname) - call s:fill(git_log_cmd) + call s:fill(b:git_log_cmd) setlocal nowrap tabstop=8 cursorline iskeyword+=# if !exists(':GBrowse') @@ -263,7 +264,15 @@ function! s:list(fugitive_repo, log_opts) call s:maps() call s:syntax() redraw - echo 'o: open split / O: open tab / gb: GBrowse / q: quit' + echo 'o: open split / O: open tab / gb: GBrowse / r: refresh / q: quit' +endfunction + +function! s:refresh() + " refresh current GV buffer + setlocal modifiable + normal! gg"_dG + setlocal nomodifiable + call s:fill(b:git_log_cmd) endfunction function! s:trim(arg) From aefcfb3a42829b3bf5aaee5a1eff45c29a6e0c3d Mon Sep 17 00:00:00 2001 From: Bertrand Sim Date: Mon, 7 Jun 2021 19:03:43 +0800 Subject: [PATCH 2/2] reorder commands in s:list, to fix b: variable not found error work out b:git_log_cmd _after_ buffer is opened --- plugin/gv.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/gv.vim b/plugin/gv.vim index a946755..34f8aac 100644 --- a/plugin/gv.vim +++ b/plugin/gv.vim @@ -247,14 +247,14 @@ function! s:log_opts(fugitive_repo, bang, visual, line1, line2) endfunction function! s:list(fugitive_repo, log_opts) - let default_opts = ['--color=never', '--date=short', '--format=%cd %h%d %s (%an)'] - let git_args = ['log'] + default_opts + a:log_opts - let b:git_log_cmd = FugitiveShellCommand(git_args, a:fugitive_repo) - let repo_short_name = fnamemodify(substitute(a:fugitive_repo.dir(), '[\\/]\.git[\\/]\?$', '', ''), ':t') let bufname = repo_short_name.' '.join(a:log_opts) silent exe (bufexists(bufname) ? 'buffer' : 'file') fnameescape(bufname) + let default_opts = ['--color=never', '--date=short', '--format=%cd %h%d %s (%an)'] + let git_args = ['log'] + default_opts + a:log_opts + let b:git_log_cmd = FugitiveShellCommand(git_args, a:fugitive_repo) + call s:fill(b:git_log_cmd) setlocal nowrap tabstop=8 cursorline iskeyword+=#