Terminal 101: Viewing and Displaying File Differences
Posted 08/06/2012 at 10:05am
| by Cory Bohon
We’ve shown how to use diff to view differences between files and folders, but the output that command provides is a little confusing, especially if you are new to using the command line. Vimdiff is much more sophisticated, but because it uses highlighting to represent changes, the output is much easier to read for new users. Let’s take a look at how to compare up to three different files with vimdiff and read the output.
Running the Command

The basics of running the vimdiff command are simple. Just type in the following command into the command line to instantly see the differences in up to three files:
vimdiff file1 file2 file3
The third file is optional, but the program does allow for up to three file comparisons at once.
Reading the Results

At first glance, you may be a bit confused at all of the highlighting and various colors, but after reading the output guide below, you’ll these colors are a simple visualization of the changes you made. Each file gets its own window, and the filename for each window is designated near the bottom of the pane.
Differences in a Whole Line
If a line is in one file, but not in another file, then the file containing the line will be designated in blue. The other file(s) that don’t have the line will be designated with a line of hyphens and a blue highlight.
Differences in a Partial Line
If only part of the line is different, the whole line will be highlighted roseish-pink and the partial difference will be red.
Lines are the Same
If the lines are the same, then they will appear in the files without any highlight. If many lines are the same, they may be “folded” (meaning that only a portion of the lines are visible). This will be designated with “+ [number of lines]” in the left-hand margin. You can expand these folded lines by moving the cursor to the folded line and pressing the Space key.
Jumping Between the Files
You can jump from one file in one window to another file in another window in vimdiff by pressing the Ctrl + W combo twice. This will jump between the windows from left to right and back again.
Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article's author, Cory Bohon on Twitter.