regexvimviduplicate-data

Removing contiguous duplicate lines in vi without sorting


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

Solution

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

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