Useful Meld tips/tricks for intermediate users
Meld is a feature-rich visual comparison and merging tool available for Linux. If you're new to the tool, you can head to our beginner's guide to get a quick know-how of how the utility works. However, if you've already read that, or are already using Meld for basic comparison/merging tasks, you'll be glad to know that in this tutorial, we will be discussing some really useful tips/tricks that will make your experience with the tool even better.
But before we jump onto the installation and explanation part, it'd be worth sharing that all the instructions and examples presented in this tutorial have been tested on Ubuntu 14.04 and the Meld version we've used is 3.14.2.
Meld tips/tricks for intermediate users
As you might already know (and we've also mentioned this in our beginner's guide), standard scrolling is not the only way to navigate between changes while using Meld - you can easily switch from one change to another using the up and down arrow keys located in the pane that sits above the edit area:
However, this requires you to move your mouse pointer to these arrows and then click one of them (depending on where you want to go - up or down) repeatedly. You'll be glad to know that there exists an even easier way to jump between changes: just use your mouse's scroll wheel to perform scrolling when mouse pointer is on the central change bar.
This way, you can navigate between changes without taking your eyes off them, or getting distracted.
2. Things you can do with changes
Just look at the last screenshot in the previous section. You know what those black arrows do, right? By default, they let you perform the merge/change operation - merge when there's no confliction, and change when there's a conflict in the same line.
But do you know you can delete individual changes if you want. Yes, that's possible. For this, all you have to do is to press the Shift key when dealing with changes. You'll observe that arrows get converted into crosses.
Just click any of them, and the corresponding change will get deleted.
Not only delete, you can also make sure that conflicting changes do not change the lines when merged. For example, here's an example of a conflicting change:
Now, if you click any the two black arrows, the line where the arrow points will get changed, and will become similar to the corresponding line of other file. That's fine as long as you want this to happen. But what if you don't want any of the lines to get changed? Instead, the aim is to insert the changed line above or below the corresponding line in other file.
What I am trying to say is that, for example, in the screenshot above, the need is to add 'test 2' above or below 'test23', rather than changing 'test23' to 'test2'. You'll be glad to know that even that's possible with Meld. Just like you press the Shift key to delete comments, in this case, you'll have to press the Ctrl key.
And you'll observe that the current action will be changed to insert - the dual arrow icons will confirm this.
As clear from the direction of arrows, this action helps users to insert the current change above or below (as selected) the corresponding change in other file.
3. Customize the way files are displayed in Meld's editor area
There might be times when you would want the text size in Meld's editor area to be a bit large (for better or more comfortable viewing), or you would want the text lines to wrap instead of going out of visual area (meaning you don't want to use the horizontal scroll bar at the bottom).
Meld provides some display- and font-related customization options in its Preferences menu under the Editor tab (Edit->Preferences->Editor) where you'll be able to make these kind of tweaks:
So here you can see that, by default, Meld uses the system defined font width. Just uncheck that box under the Font category, and you'll have a plethora of font type and size options to select from.
Then in the Display section, you'll see all the customization options we were talking about: you can set Tab width, tell the tool whether or not to insert spaces instead of tabs, enable/disable text wrapping, make Meld show line numbers and whitespaces (very useful in some cases) as well as use syntax highlighting.
4. Filtering text
There are times when not all the changes that Meld shows are important to you. For example, while comparing two C programming files, you may not want changes in comments to be shown by Meld as you only want to focus on code-related changes. So, in that case, you can tell Meld to filter (or ignore) comment-related changes.
For example, here's a Meld comparison where comment-related changes are highlighted by the tool:
And here's the case where Meld has ignored the same changes, focusing only on the code-related changes:
Cool, isn't it? So, how did that happen? Well, for this, what I did was, I enabled the 'C comments' text filter in Edit->Preferences->Text Filters tab:
As you can see, aside from 'C comments', you can also filter out C++ comments, Script comments, leading or all whitespaces, and more. What more, you can also define custom text filters for any specific case you are dealing with. For example, if you are dealing with log-files and don't want changes in lines that begin with a particular pattern to be highlighted by Meld, then you can define a custom text filter for that case.
However, keep in mind that in order to define a new text filter, you need to know Python language as well as how to create regular expressions in that language.
All the four tips/tricks discussed here aren't very difficult to understand and use (except, of course, if you want to create custom text filters right away), and once you start using them, you'll agree that they are really beneficial. The key here is to keep practicing, otherwise any tip/trick you learn will slip out of your mind in no time.
Do you know or use any other intermediate level Meld tip or trick? If yes, then you are welcome to share that in comments below.