How to use Vim to quickly see Mercurial or Git changes

As I'm editing a file in Vim, I would like to quickly highlight any changes I have made since my last commit, while still being able to edit the file. Is there anything that comes close to doing this?

Answers


Try vcscommand plugin, use :VCSVimDiff to view differencies with current revision (supports both hg and git, probably some other SCM systems as well) and internal :bdelete (:bd) (on opened buffer of course, not on already existing) to stop diffing. If you are using gentoo, it is available in the repository: app-vim/vcscommand.


Have a look at Tim Pope's fugitive.vim plugin.

I'm a git purist and usually drop into the command line for git, but when I'm in vim I find that this does most of what I need to do and yet I can still call git commands directly.


There's a new plugin that does this: vim-gitgutter. It puts the changes in the Vim gutter whenever you save the file. Here's what it looks like in action:


one method is to do the following:

:!git diff

This will show the changes (to all files) in comparison to HEAD

to do a single file :!git diff path/to/file

this is a quick way of doing it without switching different apps nor installing any plugins (which isn't always easy to do on some systems that you don't have control over).

it wont give you 'inline' highlighting but should work ok.

another way to do it quickly is to do a :r !git diff take a look at the changes then type u to undo the addition. This works nicely too, esp if you want to yank some text from HEAD


There is a site on using git and vim together:

http://www.osnews.com/story/21556/Using_Git_with_Vim

I use the git.vim one, and every time I need a diff I can check it with \gd.


How about this (no plugins required):

:new | r ! hg annotate -un #

This run hg annotate on the filename of the current buffer, then dumps the output in a new buffer.

This form of command is obviously not specific to git and hg. You can capture the results of any shell command this way.


This works for both Hg and Git: https://github.com/mhinz/vim-signify


For Mercurial, an equivalent of fugitive is lawrencium: http://bolt80.com/lawrencium

It supports both side-by-side diff and a highlighted diff-like view (basically what you get from hg diff <file>.

(disclaimer: I'm the author)


Need Your Help

Android : Persisting object(s) between BroadcastReceiver.onReceive() calls

android broadcastreceiver

I have an app that receives SMS and starts certain "work", now this work is done through Camera and some other third party APIs. So when I receive the appropriate START message (SMS) for my app, I...

Why does Eclipse + ADT plugin keep the CPU at 100%

android eclipse cpu-usage adt

The second I open up layout.xml file from a simple skeleton app in Eclipse example plugin, the cpu usage locks up to 25% IE. 1 full core. and it's been on like this for the last 30minutes I wanted ...