How to Compare and Merge Text Files on Linux using Desktop Tools (part 2)

On this page

  1. Meld
  2. Vim

This post is a response to the overwhelming comments about Meld (and other tools) in my previous article on text file comparison and merging tools. While my intention wasn't to focus on code text only but to also present something useful to word editors and writers as well, the coder's community objected to the “shallowness” of the previous post so here we go with part 2.

Meld

Start Meld and hit the “File Comparison” button located in the center. Next, press the two buttons that just appeared under the initiating options and choose the files you want to compare.

After the files are loaded, Meld indicates clearly all of the differences between the two files on its neat interface. The arrow buttons on the top panel can be used to navigate to the next/previous difference. In the “Changes” menu located in the top panel, you will find merging options. Only valid entries are available though.

Meld also supports syntax highlighting for easier review of the text. Select the “Edit” menu on the top and choose “Preferences”. From there, choose the first tab (Editor) and tick the “Use Syntax Highlighting” entry to enable the feature.

You can even add a third file for comparison by ticking the “3-way comparison” option on the initial screen. Folder comparisons are also possible on Meld.

Vim

Another (apparently) popular choice for text comparison is the “vimdiff” command. Open a terminal in the location of the two text files and type the vimdiff command followed by the two filenames: “vimdiff filename_one.h filename_two.h”

This will display the two files with highlighting on the changes. Syntax highlighting is also available so you can easily browse and read the files. You can also add more than two text files on the command if you have enough space for it.

If you don't like the terminal, you can always open Gvim and choose the “File/Split Diff” option to load the text files.

There are some vimdiff commands that you can use to merge the text of the compared files. To merge changes from the right to the left, you can use the “do” parameter, while the opposite is done with the “dp” command. Before proceeding to merge though, you may want to jump to the changes (next/previous) for the last review. This is done with “[c” and ”]c” which correspond to “previous” and “next” changes.

If the above is still not what you were looking for, you may also take a look at Beyond Compare, Xxxdiff, Kompare, and KDiff3. They have their pros and cons, but generally, all of them work well. If I had to choose one tool from both posts, I would choose Meld for its straightforward graphical interface and “coolest looking” and most accurate highlighting. And if you are looking for a commanline tool, check out sdiff.

Share this page:

3 Comment(s)