Comparing text files on Emacs

diff()emacs

I have a couple of questions about comparing text files on Emacs

  1. I have been playing with M-x compare-windows and I read in the documentation that, if I pass it a numeric argument, Emacs ignores whitespaces on the comparison, but how do I pass a numeric argument to this command? (e.g.. if I type M-x compare-windows and then I press space, it will try to autocomplete with a -)

  2. Are there any other more powerful tools or plugins for Emacs (maybe third-party?) for comparing text files?

    For example, on WinMerge for Windows, you can compare two documents side-by-side and the program automatically highlights the differences. On WinMerge I can also simultaneously scroll both windows, and it aligns regions with identical text on both windows for easy comparison. See a snapshot here.

    Is there anything like this for Emacs?

Best Answer

To pass a numeric argument to a command, enter the argument first. For example, Escape 3 Left moves 3 characters left. So type ESC 3 ESC x compare-windows RET or M-3 M-x compare-windows RET.

The most frequently used commands to compare two files are those of ediff. You can invoke them from the “Tools > Compare (Ediff)” menu. There is a command called ediff-windows-linewise, though usually you would compare two buffers (ediff-buffers) or two files (ediff-files) or two revisions under a version control system (ediff-revision). Press n and p to navigate between diff regions; press ? to see more available commands.

Related Question