Friday, August 05, 2005

gvimdiff

Gvimdiff is a feature of gvim which shows the differences between two files. The value it adds to diff is that rather than tell you that given lines are different in two files, it shows both files side-by-side and highlights and colours the precise difference.

For example, if you have:

File 1:
Hello There
Testing, Testing, 1, 2, 3
X Y Z

File 2:
Hello World
Testing, Testing, 1, 2, 3
X Y Z
A B C

then the first line in each file is shown in pink (to indicate that the lines differ) while the substrings "There" and "World" will be highlighted in red (to indicate the exact difference between those lines). The line "A B C" will be highlighted in blue (to indicate that it appears in only one of files) while the remaining lines will not be highlighted (to indicate that they appear the same in both files).

However, gvimdiff does not run properly on Windows; you get the error message "Cannot create diffs". To fix this problem, you need to install the diff program and its location must be part of the environment variable $PATH. Windows does not come with diff. (It is a UNIX utility). You can obtain a copy by installing GnuWin32 DiffUtils. Then navigate to Control Panel -> System -> Advanced and click on the button "Environment Variables" and append a semi-colon (";") plus the installation location of diff.exe (default of "C:\Program Files\GnuWin32\bin") to the Path entry. Afterward, you should be able to run gvim and successfully use the "Split diff with..." option under the "File" menu to use gvimdiff.

No comments: