在VIm中,如何删除某处重复的所有行? [英] In VIm, how to remove all lines that are duplicate somewhere?

查看:777
本文介绍了在VIm中,如何删除某处重复的所有行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下内容的文件:

I have a file that contains lines as follows:

one one
one one
two two two
one one
three three
one one
three three
four

我想从文件中删除所有重复行,只保留非重复行.因此,在上面的示例中,结果应为:

I want to remove all occurrences of the duplicate lines from the file and leave only the non-duplicate lines. So, in the example above, the result should be:

two two two
four

我看到了这个类似问题的答案.我试图按如下所示修改前单线纸:

I saw this answer to a similar looking question. I tried to modify the ex one-liner as given below:

:syn clear Repeat | g/^\(.*\)\n\ze\%(.*\n\)*\1$/exe 'syn match Repeat "^' . escape(getline ('.'), '".\^$*[]') . '$"' | d

但是它不会删除重复出现的所有行,只会删除某些重复出现的行.

But it does not remove all occurrences of the duplicate lines, it removes only some occurrences.

我该如何在vim中执行此操作?或具体来说,我该如何在vim中使用ex?

How can I do this in vim? or specifically How can I do this with ex in vim?

为了澄清,我不是在寻找sort u.

To clarify, I am not looking for sort u.

推荐答案

我的 PatternsOnText插件 1.30版现在有一个

My PatternsOnText plugin version 1.30 now has a

:DeleteAllDuplicateLinesIgnoring

命令.没有任何参数,它将按照您的问题中的说明进行工作.

command. Without any arguments, it'll work as outlined in your question.

这篇关于在VIm中,如何删除某处重复的所有行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆