How do I browse the full commit history of the current file using vim-fugitive?
Answer
:G log -- %
Explanation
vim-fugitive's :G log -- % loads the git commit history for the current file into a quickfix-style log buffer. Each commit is an entry you can navigate and open, letting you step through every revision of the file without leaving Vim — no terminal pane required.
How it works
:Gruns anygitsubcommand inside Vim; here it runsgit log-- %means "only show commits that touched this file" (the%expands to the current buffer's path)- The resulting fugitive log buffer lists commits chronologically, newest first
- Press
<CR>on a commit line to open that revision of the file as a read-only buffer - From there, press
oto open a diff against the previous revision
Example
:G log -- %
You'll see output like:
commit a3f9c12 Fix off-by-one error in parser
commit 87d1e44 Add unit tests for tokenizer
commit 3c0029a Initial implementation
Navigate with j/k, hit <CR> to inspect any version.
Tips
- Add
-pflag (:G log -p -- %) to include the full patch diff inline in the log - Use
:G log --follow -- %to trace the history even through file renames - Combine with
:Gclog -- %(older syntax) to load results into the quickfix list instead, enabling:cnext/:cprevnavigation through commits