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.
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 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 opens a split window with the output of the git diff command on the current file.
GitLog
:GitLog to show the commit log of the current file.
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
This is when someone has to say:
“Vim is a great Operating System, it just lacks a decent text editor”
And then someone replies:
“:set compatible”
Otherwise, very cool
i think your quote was directed at Emacs not Vim
Oh, really? You are so sharp.
😉
Analogously, git is a decent content-addressable tree storage. Someone just needs to write a command line wrapper for it, and provide english localization for the error messages.
Nice feature to a nice editor
Real men use Notepad.
Indeed.â–®I think especially its unique line-breaking approach deserves more recognition.â–®We as users should put more pressure on emacs/vim developers to implement compatible support.â–®
Edited 2009-05-26 13:15 UTC
Only men that still like to play with toys.
real programmers use… http://xkcd.com/378/
Bah, amateur. Not hardcore enough for edlin?
Good article. I’ve been looking for good GIT tools for VIM. GIT is becoming more and more popular in the open source world. It seems like everyone is moving away from subversion to GIT and good VIM integration is much neeeded.
It’s called “bash”, and you can launch it using the key sequence :!
🙂
Is there something similar for mercurial?
VCSCommand is a Vim Plugin that can handle multiple source control backends via Vim.
http://www.vim.org/scripts/script.php?script_id=90
In its original form it only supports SVN, CVS, GIT and SVK, but you can install the following plugin which adds Hg support to VCSCommand.
http://www.vim.org/scripts/script.php?script_id=1898
I have tried a few GUI frontend to Git and so far found none that suits my needs. I hasn’t tried this one for Vim, but I found that command-line Git is quite easy to learn and fast. I have extensively used GUIs for Subversion, but that is not required anymore with Git .