Ediff - All About The Emacs Diff Comparison Tool

Ranked #3,602 in Computers & Electronics, #65,597 overall

What is Emacs Ediff?

Ediff is a tool for comparing two different pieces of text. How is that useful? Well, consider if you sent an article for someone to proofread. When they send you the revised article (and a bill) how do you find out what they changed? Ediff is the answer to that question.

What is Ediff Really For?

It was designed as a programming tool

In fact ediff isn't really for seeing the differences between two different articles. What it is really for is to see changes made in programming source code. This is usually a far more critical task than reviewing articles as a change to code will have an effect on how a computer executes it whether you see it or not1. Humans are much better able to skim over little errors without any problem.

Tools to see changes in source code have existed, almost since the beginning of time. A particularly venerable classic is called diff which is still in use today. Could you use diff to see changes in your article?

Comparison Examples

The story of green dragons

Say you had two sentences, one of the sentences says:

I was walking through the woods when suddenly a large green dragon jumped out from behind a tree.

the other sentence says:

I was walking through the woods when suddenly a huge green dragon jumped out from behind a a tree.

What Diff Shows You

The difference is a little difficult to see

What does diff make of this? Unfortunately, the only thing it tells you is that the line has changed, not what has changed. It marks modified lines with '!', additional lines with '+' and lines that have been removed with '-'. Contrast that with ediff.

What Ediff Shows you

The changed words are well highlighted

As you can see, the difference is striking. Ediff accurately pinpoints the changes and I can immediately tell that the large dragon is now a huge dragon and a second a has been accidentally added to the line.

Can you imagine the value of this if I need to check the changes over an entire manuscript?

Essential ediff commands

The two functions I use from ediff all the time are ediff-buffers and ediff-revision. ediff-buffers is for when I don't have the files under source code control. I load the different versions of the file and diff them. However, I prefer to control my files with some kind of revision control system and check them in and out frequently (emacs makes this really easy with C-v v). Then I can see what changed since the last check-in with ediff-revision.

Once I am actually in an ediff session, the most useful commands are obviously ediff-next-difference and ediff-previous-difference which are bound to n and p. a and b are also pretty useful for copying the difference from buffer a into buffer b or vice versa. I generally set auto refinement with @ and ignore whitespace differences with ##.

Other useful ediff commands

Which other keys might you use?


  • #c - ignore case

  • m - wide display and

  • ! - update diff after you've made changes.

Curious Programmer Emacs Blog

Loading

Other Emacs Lenses

Loading

Leave Me Feedback

Any tips for improvement, congratulations or criticism is welcome here

by

jareddavison2009

My Emacs Lenses:
Creating An Emacs Command
Emacs Hooks - An Introduction
All About Ediff
more »

Feeling creative? Create a Lens!