How do I run an interactive git blame inside Vim?
Answer
:Git blame
Explanation
The vim-fugitive plugin by Tim Pope provides a powerful interactive :Git blame that goes far beyond the basic command-line git blame. It opens a scroll-bound vertical split showing blame annotations alongside your code, letting you explore the full history of every line without leaving Vim.
How it works
With the current file open, run:
:Git blame
This opens a vertical split on the left with commit hashes, authors, and timestamps for every line. The split is scroll-bound to your code, so scrolling one pane scrolls both.
Navigating blame
The blame buffer has special key mappings — press g? to see them all. The most powerful ones:
| Key | Action |
|---|---|
<CR> |
Open the commit that last changed this line |
o |
Open the commit in a horizontal split |
O |
Open the commit in a new tab |
p |
Open the commit in a preview window |
- |
Re-blame at the parent of the commit on this line |
~ |
Re-blame at the commit on this line |
P |
Re-blame at the parent, restricted to the current file |
Drilling through history
The - key is the real power move. When you see a suspicious commit in the blame output, press - on that line to re-blame the file as it existed before that commit. This lets you walk backward through the complete history of a line, peeling away each change layer by layer.
Press <CR> on any line to jump into the full commit and inspect all of its changes.
Blame a range
You can blame only specific lines by passing a range:
:10,25Git blame
Or select lines in visual mode first, then run :Git blame to blame just that range.
Tips
- Use
:Git blamewith no filename argument to blame the current file automatically - Press
qto close the blame split - Combine with
:GBrowsefrom the blame buffer to open the commit on GitHub - Fugitive respects
.mailmapfor author name normalization