vimtricks.wiki Concise Vim tricks, one at a time.

How do I open a vertical diff between index and working tree for the current file in vim-fugitive?

Answer

:Gvdiffsplit!

Explanation

When reviewing staged versus unstaged changes, jumping between terminal git commands and editor windows is slow. Fugitive's :Gvdiffsplit! opens a focused vertical diff for the current file directly inside Vim, so you can inspect hunks and resolve edits without leaving your editing context.

How it works

  • :Gvdiffsplit! is a fugitive command that opens a vertical diff layout
  • It compares the working tree version of the current file against the index/HEAD context
  • The ! variant asks fugitive to prefer vertical layout behavior and is often easier to scan on wide monitors
  • Once in diff mode, you can use standard Vim diff motions and operations like ]c, [c, :diffget, and :diffput

Example

From a file with both staged and unstaged edits:

:Gvdiffsplit!

Use ]c to jump hunk by hunk, then apply targeted transfers with:

:diffget

This lets you reconcile sections interactively before finalizing commits.

Tips

  • Pair with :Gwrite to stage the current buffer quickly after resolving hunks
  • Use :Gvdiffsplit HEAD~1 when you want to compare against an explicit commit
  • Close the diff layout cleanly with :diffoff! when done

Next

How do I append the current filename to a named register from Ex command-line?