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?

App of the Day: Sublime Text 2

Sublime Text 2 IconThere are a lot of different text/code editors out there. Some people swear by Coda ($99) or TextMate (~$50). Others prefer TextWrangler because it’s free and still has plenty of power to get the job done. If your a PC person, Notepad++ may be your weapon of choice. This post isn’t meant to be a review or comparison of the different text editors out there, but simply an introduction to another awesome alternative that I think is more unheard of than not.

Last summer a close friend referred me to Sublime Text 2. Before Sublime, I used TextWrangler, and I gotta say, the wrangler is great, but I just didn’t connect with it for some reason. I’ll admit, I didn’t really research all its functionality or install very many plugins, but I’ve heard great things. Regardless, Sublime resonated with me instantly.

Sublime is clean; no buttons all over the place. It’s got this awesome “1000 ft” distance view that can be used to scroll fast through code or find a section of your code through pattern recognition in the line structure. I’ve found it very helpful since I often use it to look through error stack traces, which are very pattern prone and are often thousands of lines long. Sublime has syntax highlighting for just about every language possible (much like other editors). You can control the preferences really easily too, changing just about any functionality. For example if you don’t like the “1000 ft view,” you can turn that off. Did I mention autocomplete? Yup…and while this isn’t language specific, it’s surprisingly smart and very helpful. Not nearly as powerful as autocomplete in Xcode, NetBeans or the like, but still a very useful feature.

These are just a few of the features that came to mind first and that I’ve found very helpful. Here’s a list of a few more (This comes straight from the documentation):

Usage

Customization

Miscellaneous

API

Oh and…Sublime is pretty platform agnostic. It’s available on Mac OS X, Linux and Windows (32- & 64-bit). You can also download “portable” versions for Windows that are self-contained so if you just want to try it out or keep it lite, you don’t have to worry about it installing extra garbage in your registry or system folders.

Sublime isn’t technically “free.” Here’s what the author has to say about that:

Sublime Text 2 may be downloaded and evaluated for free, however a license must be purchased for continued use. There is currently no enforced time limit for the evaluation.

So in other words, you can use it indefinitely without any limitations. I think it asks you to buy a license after every 25 saves or something? I didn’t find it very annoying personally. After I realized I really liked it, I just asked my company to buy me a license for work. The downside is that if you can’t work a deal like that then it costs $59 for one license.

Try it out and tell me what you think. What’s it missing? Would you switch?

*UPDATE* You should really check out Tuts+ for a list of very useful tips and tricks for Sublime Text 2. It will blow your mind if you don’t know about these features already.

Sublime Syntax Spell Checking

Syntax Spell Checking

Sublime Syntax Highlighting Javascript in HTML in PHP

Syntax Highlighting Javascript in HTML in PHP? No problem...

Sublime Multiple Selections

Make Multiple Selections

Sublime Find and Replace with Regex

Find and Replace with Regex

Sublime Edit Side-by-Side

Editing side-by-side