Rook
Rook

Reputation: 62548

How to highlight adjacent duplicate lines

Is there a way to highlight duplicate lines in Vim, in a file, BUT only if they're adjacent to each other, i.e. if there is a line (in line 1) and there is a duplicate of that line (in line 99), do not highlight that.

But if there is a line in (line n), and there is a duplicate of that line in lines (either, n-1 or n+1) highlight those (or just duplicates).

Is it something regex can accomplish?

(this is waaay off my regex skills)

Upvotes: 2

Views: 1894

Answers (2)

ib.
ib.

Reputation: 28964

Try the following custom match pattern.

:match Conceal /^\(.*\)\n\%(\1\n\)\+/

Use

:match none

to disable previously defined highlighting.

Upvotes: 0

Zsolt Botykai
Zsolt Botykai

Reputation: 51643

Try this:

:set hls
/^\(.*\)\n\1$

Upvotes: 5

Related Questions