Side-by-Side File Comparison Plugin for Sublime

I found a nice side-by-side file comparison plugin for Sublime called Glue Views. Something cool about Glue Views is that it supports more than two files at a time. The plugin’s developer has a number of other free packages available for Sublime, including similar diff tools.

On the Sublime feature request forum I noticed a number of folks want the developer to include diff-merge features in Sublime by default. I already use other diff-merge tools specifically for merging conflicts in Git and the like, so that’s not exactly what I was looking for when I found this plugin. For those looking for that kind of functionality, some forum posters have recommended using existing TextMate packages since they are supporter by Sublime without modification. If your interested in learning more, this thread is a good place to start.

To install Glue Views or other Sublime packages on a Mac (the process and location is similar on Windows), simply navigate to /Users/<user account>/Library/Application Support/Sublime Text 2/Packages/User (Cmd + Shift + G in Finder). Copy the *.py package into that directory and Sublime will automatically detect it and compile. In the case of Glue Views, the developer included sample key bindings within the comments of the Python code. His didn’t work for me so I created my own:

[
   { "keys": ["alt+equals"], "command": "glue_views_add"},
   { "keys": ["alt+minus"], "command": "glue_views_remove"},
   { "keys": ["ctrl+alt+0"], "command": "glue_views_clear"}
]

Paste those into the Default (OSX).sublime-keymap file. If you want a separate menu for the plugin or all your plugins, create a file (in the same directory listed above) named Main.sublime-menu and put something similar to the following in it:

[
   {
      "caption": "Plugins",
      "mnemonic": "l",
      "id": "plugins",
      "children":
      [
         {
            "caption": "Glue",
            "mnemonic": "G",
            "id": "glue",
            "children":
            [
               { "command": "glue_views_add", "caption": "Add View", "mnemonic": "A" },
               { "command": "glue_views_remove", "caption": "Remove View", "mnemonic": "R" },
               { "command": "glue_views_clear", "caption": "Clear Views", "mnemonic": "C" }
            ]
         }
      ]
   }
]

That gives you a permanent Plugins menu to which you can add menus and commands for other plugins.

Compare Files Line-by-Line (or Image-to-Image)

Two of my favorite tools for line-by-line text comparison are diff and FileMerge. One reason why I like them so much is because they are lightweight alternatives for word processors like Microsoft Word, which you wouldn’t be inclined to open for coding (that’s one of my primary uses).

diff is a simple CLI-based tool accessible on most *nix systems. The basic format is diff <options> <file1> <file2>. It comes with a lot of powerful options too. To list a few:

  • Ignore tab expansion, blank lines, and other white space
  • Ignore case
  • Ignore matching lines
  • Side-by-side output
  • Compare files in directories
  • Recurse through subdirectories
  • Reporting identical files or simply whether or not differences exist

FileMerge is as simple as it gets for file comparison with a GUI. FileMerge comes with any installation of Xcode so it’s basically free. However, you’ll have to download the whole Xcode package (~1 GB) to get it unless you can find it floating around on the net alone.

FileMerge Screenshot

FileMerge allows you to select the changes you want to keep through a menu at the bottom-right that designates the favored document. By default, the right (as opposed to left) document is selected. Below the two separate documents is the final output that will result from the merge. FileMerge also allows you to edit/add content in this section before merging and saving.

As I was writing this post, I got a referral from Russ to a cross-platform comparison tool called Perforce. The cool thing about Perforce (besides being platform agnostic) is it compares not only files and folders, but images too. Not to mention it’s FREE. I only briefly read about it and watched some sample videos on the site, but it’s pretty powerful. It also can be used in parallel with Git. Read about it here.

After the recommendation to checkout Perforce, I started doing some more research and stumbled upon a couple other tools. First off, free code editor TextWrangler (Mac) includes file comparison. Diffmerge seems like a really cool alternative. It’s also free, available on multiple pllatforms and includes merging of 3 files and integration with Windows Explorer. Kaleidoscope is another option, though you’ll have to pay ~$40. It includes many of the same features as Perforce.

What do you use when you need to compare files? Have any recommendations?