给中级 Meld 用户的有用技巧
Meld
![](/data/attachment/album/201708/25/081212g4ub334ub4am4a04.jpg)


Meld 是 Linux 上功能丰富的可视化比较和合并工具。如果你是第一次接触，你可以进入我们的[初学者指南](/article-8402-1.html)，了解该程序的工作原理，如果你已经阅读过或正在使用 Meld 进行基本的比较/合并任务，你将很高兴了解本教程的东西，在本教程中，我们将讨论一些非常有用的技巧，这将让你使用工具的体验更好。


*但在我们跳到安装和解释部分之前，值得一提的是，本教程中介绍的所有说明和示例已在 Ubuntu 14.04 上进行了测试，而我们使用的 Meld 版本为 3.14.2*。


### 1、 跳转


你可能已经知道（我们也在初学者指南中也提到过这一点），标准滚动不是在使用 Meld 时在更改之间跳转的唯一方法 - 你可以使用向上和向下箭头键轻松地从一个更改跳转到另一个更改位于编辑区域上方的窗格中：


 [![Navigating in Meld](/data/attachment/album/201708/25/083846b58ldk85olo3389n.png)](https://www.howtoforge.com/images/beginners-guide-to-visual-merge-tool-meld-on-linux-part-2/big/meld-go-next-prev-9.png) 


但是，这需要你将鼠标指针移动到这些箭头，然后再次单击其中一个（取决于你要去哪里 - 向上或向下）。你会很高兴知道，存在另一种更简单的方式来跳转：只需使用鼠标的滚轮即可在鼠标指针位于中央更改栏上时进行滚动。


 [![The change bar](/data/attachment/album/201708/25/083847dsmshxwbmmbbbkwf.png)](https://www.howtoforge.com/images/beginners-guide-to-visual-merge-tool-meld-on-linux-part-2/big/meld-center-area-scrolling.png) 


这样，你就可以在视线不离开或者分心的情况下进行跳转，


### 2、 可以对更改进行的操作


看下上一节的最后一个屏幕截图。你知道那些黑箭头做什么吧？默认情况下，它们允许你执行合并/更改操作 - 当没有冲突时进行合并，并在同一行发生冲突时进行更改。


但是你知道你可以根据需要删除个别的更改么？是的，这是可能的。为此，你需要做的是在处理更改时按下 Shift 键。你会观察到箭头被变成了十字架。


 [![Things you can do with changes](/data/attachment/album/201708/25/083847goh999xy9rapzyxn.png)](https://www.howtoforge.com/images/beginners-guide-to-visual-merge-tool-meld-on-linux-part-2/big/meld-delete-changes.png) 


只需点击其中任何一个，相应的更改将被删除。


不仅是删除，你还可以确保冲突的更改不会在合并时更改行。例如，以下是一个冲突变化的例子：


 [![Delete changes in Meld](/data/attachment/album/201708/25/083852mxhmzbfnhqh1bhtb.png)](https://www.howtoforge.com/images/beginners-guide-to-visual-merge-tool-meld-on-linux-part-2/big/meld-conflicting-change.png)  


现在，如果你点击任意两个黑色箭头，箭头指向的行将被改变，并且将变得与其他文件的相应行相似。只要你想这样做，这是没问题的。但是，如果你不想要更改任何行呢？相反，目的是将更改的行在相应行的上方或下方插入到其他文件中。


我想说的是，例如，在上面的截图中，需要在 “test23” 之上或之下添加 “test 2”，而不是将 “test23” 更改为 “test2”。你会很高兴知道在 Meld 中这是可能的。就像你按下 Shift 键删除注释一样，在这种情况下，你必须按下 Ctrl 键。


你会观察到当前操作将被更改为插入 - 双箭头图标将确认这一点 。


 [![Change actions](/data/attachment/album/201708/25/083852rlyuju9zjyctcbjj.png)](https://www.howtoforge.com/images/beginners-guide-to-visual-merge-tool-meld-on-linux-part-2/big/meld-ctrl-insert.png) 


从箭头的方向看，此操作可帮助用户将当前更改插入到其他文件中的相应更改 (如所选择的)。


### 3、 自定义文件在 Meld 的编辑器区域中显示的方式


有时候，你希望 Meld 的编辑区域中的文字大小变大（为了更好或更舒适的浏览），或者你希望文本行被包含而不是脱离视觉区域（意味着你不要想使用底部的水平滚动条）。


Meld 在 *Editor* 选项卡（*Edit->Preferences->Editor*）的 *Preferences* 菜单中提供了一些显示和字体相关的自定义选项，你可以进行这些调整：


 [![Meld preferences](/data/attachment/album/201708/25/083856u3ut540fu6z43fyc.png)](https://www.howtoforge.com/images/beginners-guide-to-visual-merge-tool-meld-on-linux-part-2/big/meld-editor-tab.png) 


在这里你可以看到，默认情况下，Meld 使用系统定义的字体宽度。只需取消选中 *Font* 类别下的框，你将有大量的字体类型和大小选项可供选择。


然后在 *Display* 部分，你将看到我们正在讨论的所有自定义选项：你可以设置 Tab 宽度、告诉工具是否插入空格而不是 tab、启用/禁用文本换行、使Meld显示行号和空白（在某些情况下非常有用）以及使用语法突出显示。


### 4、 过滤文本


有时候，并不是所有的修改都是对你很重要的。例如，在比较两个 C 编程文件时，你可能不希望 Meld 显示注释中的更改，因为你只想专注于与代码相关的更改。因此，在这种情况下，你可以告诉 Meld 过滤（或忽略）与注释相关的更改。


例如，这里是 Meld 中的一个比较，其中由工具高亮了注释相关更改：


 [![Filter Text in Meld](/data/attachment/album/201708/25/083857wjailj1xjggbubcb.png)](https://www.howtoforge.com/images/beginners-guide-to-visual-merge-tool-meld-on-linux-part-2/big/meld-changes-with-comments.png) 


而在这种情况下，Meld 忽略了相同的变化，仅关注与代码相关的变更：


 [![Ignore Changes in Meld](/data/attachment/album/201708/25/083858tdv7ovhpviz9xxxk.png)](https://www.howtoforge.com/images/beginners-guide-to-visual-merge-tool-meld-on-linux-part-2/big/meld-changes-without-comments.png) 


很酷，不是吗？那么这是怎么回事？为此，我是在 “*Edit->Preferences->Text Filters*” 标签中启用了 “C comments” 文本过滤器：


 [![C-Comments in Meld](/data/attachment/album/201708/25/083900bc6vnhnc68hn18tk.png)](https://www.howtoforge.com/images/beginners-guide-to-visual-merge-tool-meld-on-linux-part-2/big/meld-text-filters.png) 


如你所见，除了 “C comments” 之外，你还可以过滤掉 C++ 注释、脚本注释、引导或所有的空格等。此外，你还可以为你处理的任何特定情况定义自定义文本过滤器。例如，如果你正在处理日志文件，并且不希望 Meld 高亮显示特定模式开头的行中的更改，则可以为该情况定义自定义文本过滤器。


但是，请记住，要定义一个新的文本过滤器，你需要了解 Python 语言以及如何使用该语言创建正则表达式。


### 总结


这里讨论的所有四个技巧都不是很难理解和使用（当然，除了你想立即创建自定义文本过滤器），一旦你开始使用它们，你会认为他们是真的有好处。这里的关键是要继续练习，否则你学到的任何技巧不久后都会忘记。


你还知道或者使用其他任何中级 Meld 的贴士和技巧么？如果有的话，欢迎你在下面的评论中分享。




---


via: <https://www.howtoforge.com/tutorial/beginners-guide-to-visual-merge-tool-meld-on-linux-part-2/>


作者：[Ansh](https://www.howtoforge.com/tutorial/beginners-guide-to-visual-merge-tool-meld-on-linux-part-2/) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
# 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](https://www.howtoforge.com/tutorial/beginners-guide-to-visual-merge-tool-meld-on-linux/) 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

### 1. Navigation

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.

## Conclusion

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.