browsing commits with vim
just a little vim trick
2025-08-31
So earlier I was actually using fzf as a little ad-hoc git commit browser because fzf is my favorite and I love using it as a simple little UI for stuff like this.
git log --oneline \
| fzf --tac \
--preview="git show {1}" \
--bind "enter:become(git show {1})"
It looks like this:
git show for each
commit in the preview window
And the ‘bind’ command means that pressing enter closes fzf and shows
the commit as though typing git commit <hash>.
I thought it was pretty neat!
Then I thought about how I recently switched to using vim to browse man pages, and wondered whether there was a way to also use vim to browse git commits.
You can very easily pipe some commit oneliners into vim:
git log --oneline | nvim -
From there, it’s a matter of remembering about K and
keywordprg.
Runs the program given by ‘keywordprg’ to lookup the |word| (defined by ‘iskeyword’) under or right of the cursor. Default is “man”.
:help K
If you press K on a git commit hash, you’ll get the
error ‘no man page for (hash)’
Until/unless you set the keywordprg:
:set keywordprg=git\ show
Now if you press K on a hash, you’ll get the commit
message and diff open up in a tab.
This is awesome!
With a few further tweaks, like setting the filetype with a cli flag and setting the keywordprg in a ftplugin file, you can make a little alias to have the thing ready:
alias glv='git log --oneline | nvim -R -c 'set filetype=git" -"
GIF? GIF!