How to use vimdiff

Vim can be used as a diff and merge tool. While it cannot match the beauty and power of GUI programs like Meld, it is immensely useful to diff and merge over a SSH session.

  • Vim can be invoked in diff mode either using vim -d or as vimdiff. Just pass in the names of the files to compare:
$ vimdiff 1.cpp 2.cpp
$ vim -d 1.cpp 2.cpp 3.cpp
  • Vim in diff mode displays each file in its own window side-by-side showing the diff sections in colors. You can switch between the windows using the normal Vim commands. (I use Ctrl-W-W.) And when you scroll down all the windows scroll down with you because they are locked to each other.

  • To switch to and fro between diffs use the ]-c and [-c commands.

  • To put the diff the cursor is resting on to the next window use the command dp

  • To pull the diff from the next window use the command do

Tried with: Vim 7.4 and Ubuntu 16.04


How to use Quick Diff in Eclipse

Added, modified and deleted lines marked by Quick Diff in Eclipse editor.
Added, modified and deleted lines marked by Quick Diff in Eclipse editor.

Eclipse has support for version control systems like Git, SVN and CVS. Support for Mercurial can be enabled by using the MercurialEclipse plugin. When viewing files in version control, it is common practice to quickly see which of the lines are uncommitted compared to the current head (or parent) revision. This information can be viewed in Eclipse by using its Quick Diff feature. This is easy to do:

  1. Go to Window -> Preferences -> General -> Editors -> Text Editors -> Quick Diff. This is the dialog from where it can be configured.

  2. Turn on Quick Diff, by enabling the option Enable quick diff.

  3. Choose the version control system for which Quick Diff is needed from the dropdown Use this reference source. Git, SVN and CVS should be present here. Mercurial appears if the MercurialEclipse plugin is installed.

  4. The overview ruler is the ruler to the right of the scrollbar in the editor. If you would like to see the uncommitted lines to be marked on it, enable the option Show differences in overview ruler.

  5. Choose Apply and OK. Close all editor windows and reopen the source file that you want in the editor.

You should be able to see the newly added, modified or deleted lines marked in colors in the left bar on which line numbers are usually displayed. The colors used are the ones set in the Quick Diff dialog (see above steps). You can also view these uncommitted locations marked along the overview ruler on the right.

Tried with: Eclipse Luna 4.4.1 and Ubuntu 14.04

How to use GUI diff with SVN

A GUI diff program can be used for viewing the diff in Subversion by using the --diff-cmd option. For example, to use the Meld GUI diff tool:

$ svn diff --diff-cmd meld

If you find yourself using the GUI diff frequently, consider adding an alias command to your shell that uses this option. For example, if you use the Fish shell, you can add this function:

function svnvdiff --description="SVN diff using GUI diff tool"
    svn diff --diff-cmd meld $argv

Tried with: Subversion 1.8.8 and Ubuntu 14.04

How to use ExtDiff extension of Mercurial

Mercurial is very convenient to use at the commandline. However, there are certain operations that are better with the GUI. For example, I prefer to use a GUI to go through the diff of uncommitted changes. The ExtDiff extension can be used to launch a GUI Diff tool to view the diff of a single file or across the entire repository.

  • To enable the ExtDiff extension, add this line to your hgrc:
hgext.extdiff =
  • To view the diff of a particular file using a GUI diff program, for example meld:
$ hg extdiff -p meld src/bar/foo.cpp
  • To view the diff of all uncommitted files using a GUI diff program, for example meld:
$ hg extdiff -p meld

Make sure that the GUI diff program you use has the ability to show the diff of multiple files in a directory hierarchy.

  • If you want to always launch a particular GUI diff program, then it is better to add a custom command for it. For example, to launch meld using a new command named vdiff, add this line to your hgrc:
cmd.vdiff = meld

After this, you can view the diff using the vdiff command:

$ hg vdiff src/bar/foo.cpp
$ hg vdiff

Tried with: Mercurial 2.8.2 and Ubuntu 12.04

Side-by-side color diff at terminal using CDiff


If you use Mercurial, Git or Subversion at the shell, CDiff is a useful tool to have around. By default, hg diff or git diff is displayed in the classic diff format. This shows the before-and-after changed lines one below the other. Personally, I find this very confusing. I very much prefer the side-by-side diff view used in GUI diff programs. cdiff is a great way to get this side-by-side diff view at the shell in full color!


CDiff is a Python program that can be installed from PyPI using this command:

$ sudo pip install cdiff

Note: Do not confuse this package with the colordiff package that is available in Ubuntu repositories. That is something else!


  • Invoke cdiff in any subdirectory of a Mercurial, Git or Subversion repository. By default, this shows a colorful diff of the changes in all uncommitted files.

  • To get side-by-side diff view use: cdiff -s

  • CDiff assumes that your window width is 80 by default. I prefer to view side-by-side diff that uses the full width of my terminal window. This can be achieved by invoking: cdiff -s -w 0

  • To diff two files, just pass them through diff -u and pipe that to cdiff:

$ diff -u file1.cpp file2.cpp | cdiff -s

Tried with: CDiff 0.9.7, Python 2.7.6 and Ubuntu 14.04

How to generate patch of commit in Git

You have cloned an online Git repository, ran into a bug, found the cause, fixed it and committed it. Now, you want to submit the patch of the fix to the maintainer. The Git incantation to do this is:

git format-patch origin/master

This creates a patch file that the maintainer can pull into his Git repository.

Tried with: Git 1.7.4