且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除vi中的连续重复行,不进行排序

更新时间:2023-12-04 16:52:58

刚刚找到了解决方案 here 。以下正则表达式正确工作:

  g / ^ \(。* \)$ \\\
\1 $ / d


This question already addresses how to remove duplicate lines, but enforces that the list is sorted first.

I would like to perform the remove contiguous duplicate lines step (i.e. uniq) without first sorting them.

Example before:

Foo
Foo
Bar
Bar

Example after:

Foo
Bar

Just found the solution here. The following regex works correctly:

g/^\(.*\)$\n\1$/d