git-vimEdit
git-vim is a plugin that provides access to some Git functionality from within Vim.
Where to get it
I have a fork of the official repo, with some patches to fix some minor issues:
Installation
git clone git://github.com/motemen/git-vim.git git-vim.git
cd git-vim.git
cp plugin/git.vim ~/.vim/plugin/
cp syntax/git-* ~/.vim/syntax/
Use
Key mappings
git clone git://github.com/motemen/git-vim.git git-vim.git
cd git-vim.git
cp plugin/git.vim ~/.vim/plugin/
cp syntax/git-* ~/.vim/syntax/
Key mappings
The README at the official repo provides a full list, but here are some of the most useful key mappings:
<leader>gd: calls:GitDiffwith no args (shows unstaged changes; same asgit diff)<leader>gD: calls:GitDiff --cached(shows staged changes; same asgit diff --cached)<leader>gs: calls:GitStatus(git status)<leader>gl: calls:GitLog(callsgit logfor the current file; to get the repo-wide log you have to manually do:GitLog HEAD)<leader>ga: calls:GitAddwith no args (stages the current file usinggit add)<leader>gA: calls:GitAddwith filename completion (stages the specified file usinggit add)<leader>gc: calls:GitCommit(same asgit commit; but note that if you have no staged changes then it will assumegit commit -a)
In practice I use :GitCommit -s to sign off my commits; <leader>gc is really only good for "throw-away" commits because it produces commits without signoffs.
Commands
In addition to the commands already mentioned above, some of the more useful ones include:
:Git <args>: arbitrary Git command:GitCheckout <args>: useful for resetting individual files to theHEADstate (eg.:GitCheckout HEAD -- foo.c)
There are also a bunch of other commands that I can’t really see myself using from within Vim (:GitPull, :GitPullRebase, :GitPush, :GitCatFile and so on).
Note that commands like :GitDiff and :GitCheckout complete Git commits.