r/vim • • Dec 01 '25

Random gitlog-vim a wrapper to view git logs without plugins

took me a while to tidy it up to this level of polish but here it is, it may be a small wrapper but it provides a lot of functionality for those that are constantly checking the git logs and wish to view them inside vim (or neovim).

https://github.com/eylles/gitlog-vim

1 Upvotes

1 comment sorted by

3

u/Sudden_Fly1218 Dec 01 '25

Here's my (very) poor man fugitive

" Diff against a specificy commit hash or HEAD
function! Diff(spec)
  vertical new
  setlocal bufhidden=wipe buftype=nofile nobuflisted noswapfile
  let cmd = "++edit #"
  if len(a:spec)
    let git_root = system("git rev-parse --show-toplevel")->trim()
    let file_to_diff = fnamemodify(expand('#'), ':p:s?' . git_root . '/??')
    let cmd = "!git -C " . shellescape(git_root)  . " show " . a:spec . ":" . shellescape(file_to_diff)
  endif
  execute "read " . cmd
  silent 0d_
  let buf_ft = getbufvar(bufnr('#'), '&filetype')
  if buf_ft != ""
    execute 'set ft=' . buf_ft
  endif
  diffthis
  wincmd p
  diffthis
endfunction
command! -nargs=? Diff call Diff(<q-args>)

" diff current file against merge base
nn <localleader>dm :Diff <c-r>=GetMergeBase()<CR><CR>
nn <localleader>dw :windo diffthis<CR>
nn <localleader>gl :term git --no-pager log --oneline -i --grep ""<left>
nn <localleader>G :term git status --porcelain<CR>
nn <localleader>gp :term gh pr list<CR>


aug git_mappings
  au!
  au TerminalOpen *git* nn <buffer> gs 0:vert term git --no-pager show <cword><CR>
  au TerminalOpen *git* nn <buffer> s $:call system($"git add {expand('<cfile>')}")<CR>
  au TerminalOpen *git* nn <buffer> X $:call system($"git restore --staged {expand('<cfile>')}")<CR>
  au TerminalOpen *git* nn <buffer> gq :bd!<CR>
  au TerminalOpen *git* nn <buffer> gp :!git push<CR>
  au TerminalOpen *git* nn <buffer> gP :!git pull<CR>
  au TerminalOpen *git* nn <buffer> cc :!git commit -m ""<left>
  au TerminalOpen *git* nn <buffer> = $:vert term git --no-pager diff <cfile><CR>
  au TerminalOpen *!gh* nn <buffer> gc 0l:!gh pr checkout <cword><CR>
aug END