Fugitive.vim - a complement to command line git
The fugitive plugin, by Tim Pope, is a git wrapper for Vim. It complements the command line interface to git, but doesn’t aim to replace it. In this episode, we’ll see how some of fugitive’s commands can streamline your workflow.
This is the first of a five part series on fugitive.
:Git command, you can run any arbitrary git command from inside Vim. I prefer to switch to the shell for anything that generates a log of output, such as
git log for example. But commands that generate little or no output are fair game for running from inside Vim (
:Git checkout -b experimental for example).
At Vim’s command line, the
% symbol has a special meaning: it expands to the full path of the current file. You can use this to run any git command that expects a filepath as an argument, making the command act on the current file. But fugitive also provides a few convenience methods, some of which are summarized in this table:
||Stage the current file to the index|
||Revert current file to last checked in version|
||Delete the current file and the corresponding Vim buffer|
||Rename the current file and the corresponding Vim buffer|
:Gcommit command opens up a commit window in a split window. One advantage to using this, rather than running
git commit in the shell, is that you can use Vim’s keyword autocompletion when composing your commit message.
:Gblame command opens a vertically split window containing annotations for each line of the file: the last commit reference, with author and timestamp. The split windows are bound, so that when you scroll one, the other window will follow.