Vim Fugitive is the Git integration for Vim that makes you wonder how you ever lived without it.

Let’s see it in action. Imagine you’re editing a file, and you want to see its Git history.

:Glog

This opens a new buffer showing the commit log for the current file, with each commit’s hash, author, date, and message.

Now, say you want to see the diff for a specific commit. You can navigate to a commit in the Glog buffer and press D.

commit 1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b
Author: Jane Doe <jane.doe@example.com>
Date:   Mon Jan 1 10:00:00 2024 -0500

    Refactor login module

:Glog

Pressing D on that commit will open a diff view, showing exactly what changed in that commit.

--- a/src/login.c
+++ b/src/login.c
@@ -1,5 +1,5 @@
 /* Login module */
-int login_user(char *username, char *password) {
+int login_user(const char *username, const char *password) {
     // ... implementation ...
     return 0;
 }

You can also stage and unstage files directly from Vim. If you’re in a file that has been modified, type :Gstatus.

:Gstatus

This shows you the Git status of your repository.

 M src/login.c
?? README.md

In this output, M indicates a modified file. To stage src/login.c, you can type :1 (to select the first line) and then :Gwrite.

:1Gwrite

This stages the file. The status will update:

A  src/login.c
?? README.md

A now indicates an added (staged) file. To unstage it, you’d use :1Greset.

Fugitive also makes committing a breeze. From within an editing buffer, :Gcommit will open a commit message buffer.

:Gcommit

This buffer is pre-populated with the diff of your staged changes. You write your commit message, save and close the buffer (e.g., :wq), and Fugitive will execute the git commit command for you.

The real magic of Fugitive lies in its ability to bring Git’s power directly into your editing workflow, eliminating context switching. It doesn’t just display Git information; it allows you to act on it seamlessly. You can stage, unstage, revert, diff, blame, and even rebase, all without leaving Vim.

One of the most powerful, yet often overlooked, features is the ability to stage specific hunks (sections) of a file. When you’re in a modified file and type :Gdiff, you see the diff of your unstaged changes. You can then navigate to a specific hunk and press - to stage just that hunk. This is incredibly useful for crafting atomic commits where you’ve made multiple unrelated changes in the same file.

The next step after mastering basic staging and committing is exploring branch management and rebasing.

Want structured learning?

Take the full Vim course →