Next: Code Fixing, Previous: Coding Standard, Up: Tools

### 13.3 Visual Comparison

The visual comparison, available either from the VCS menus or from the Tools menu, provide a way to display graphically differences between two or three files, or two different versions of the same file.

The 2-file comparison tool is based on the standard text command `diff`, available on all Unix systems. Under Windows, a default implementation is provided with GPS, called `gnudiff.exe`. You may want to provide an alternate implementation by e.g. installing a set of Unix tools such as cygwin (http://www.cygwin.com).

The 3-file comparison tool is based on the text command `diff3`, available on all Unix systems. Under Windows, this tool is not shipped with GPS. It is available as part of cygwin, for example.

When querying a visual comparison in GPS, in Side_By_Side mode, the user area will show, side by side, editors for the files involved in the comparison. The reference file is placed by default on the left side. When in Unified mode, GPS will not open a new editor, but will show all the changes directly in the original editor. Note that Unified mode is relevant only when comparing two files: when comparing three files, the Side_By_Side mode is used.

Color highlighting will be added to the file editors:

gray
  This color is used for all the chunks on the reference (left) file. Only the modified (right) file is displayed with different colors.
yellow
  This color is used to display lines that have been modified compared to the reference file. When there are fine differences within one line, they are shown in a brighter yellow.
green
  Used to display lines added compared to the reference file; in other words, lines that are not present in the reference file.
red
  Used to display lines removed from the reference file; in other words, lines that are present only in the reference file.

These colors can be configured, see The Preferences Dialog.

As with all highlighted lines in GPS, the visual differences highlights are visible in the Speed Column at the left of the editors.

Blank lines are also added in the editors, in places that correspond to existing lines in the other editors. The vertical and horizontal scrolling are synchronized between all editors involved in a visual comparison.

When a visual comparison is created, the Locations View is populated with the entries for each chunk of differences, and can be used to navigate between those.

Closing one of the editors involved in a visual comparison removes the highlighting, blank lines, and scrolling in the other editors.

Editors involved in a visual comparison have a contextual menu `Visual diff` that contains the following entries:

`Recompute`
  Regenerates the visual comparison. This is useful, for example, when one of the editors has been modified by hand while it was involved in a visual comparison
`Hide`
  Removes the highlighting corresponding to the visual comparison from all editors involved
`Close editors`
  Closes all editors involved in this visual comparison
`Use this editor as reference`
  Change the reference to this editor. (This is only visible when displaying a visual comparison involving 3 files).