Using Git with Vim

I recently started using Git for my local revision control. Since I spend about 90% of my coding time inside the Vim editor, I went looking for a plugin that would make Vim play nice with Git. In this article I present two different vim plugins and explore their feature-set via screenshots.

My expectations from a git plugin were rather simple.

  • Display the active git branch of current file.
  • Switch between different branches, without quitting Vim.
  • Multi-platform support.

I found two competing plugins that satisfied my needs: git-branch-info.vim and git.vim.

git-branch-info.vim

This plugin was designed to display the current branch info in the vim status line.

set laststatus=2 " Enables the status line at the bottom of Vim
set statusline=%{GitBranchInfoString()}

In addition to the current branch info, it can also list all the branches in the current git repo through a menu (only in gVim) and allows to checkout/fetch a particular branch.

git-branch-info.vim

One caveat of this plugin is it’s designed with a Linux user in mind and it didn’t work in windows in its original form. Since it was project hosted on Github, I decided to fork it and make a windows version of the plugin. The windows version can be downloaded from the project’s windows fork.

git.vim

Git.vim is a more comprehensive plugin that allows the user to perform a lot more Git operations from within the Vim environment. The github home page for this plugin has a list of all the functionalities available through this plugin.

The name of the function called to set the status line is GitBranch(). So the lines added to .vimrc will be,

set laststatus=2
set statusline=%{GitBranch()}

But unfortunately there is a bug in the GitBranch() function. Once again Github to the rescue, the project is forked and the bug fixed fork can be downloaded here. A pull request is submitted to the author to fix this bug.

Some of the other features of this plugin are showcased below. This plugin comes with syntax files that hightlights the git log, git diff and git commit messages. The syntax highlighting can be seen in the screenshots shown below.

GitCommit

GitCommit

:GitCommit opens a split window to enter the log message and commits the current file to the repository. If no files are staged to the index, it will automatically use git commit -a option to stage all the changed files and commit them to the repository.

GitDiff

GitDiff

:GitDiff opens a split window with the output of the git diff command on the current file.

GitLog

GitLog

:GitLog to show the commit log of the current file.

GitBlame

GitBlame

:GitBlame Shows the changes made to a file on a line-by-line basis, by displaying the name of the user next to each line in a vertical split.

There is an experimental feature for merging files with conflicts using Vimdiff :GitVimDiffMerge and any other git command can be called from Vim by issuing :Git . Unlike git-branch-info.vim, the git.vim plugin is OS agnostic.

15 Comments

  1. 2009-05-26 12:59 pm
    • 2009-05-26 4:48 pm
      • 2009-05-27 12:01 am
    • 2009-05-26 6:44 pm
  2. 2009-05-26 1:01 pm
  3. 2009-05-26 1:03 pm
    • 2009-05-26 1:14 pm
    • 2009-05-26 1:24 pm
    • 2009-05-26 2:57 pm
    • 2009-05-26 3:33 pm
  4. 2009-05-26 1:20 pm
  5. 2009-05-26 1:23 pm
  6. 2009-05-26 2:59 pm
  7. 2009-05-27 9:22 pm