2

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)

David Brown
  • 13,336
  • 4
  • 38
  • 55
Rook
  • 60,248
  • 49
  • 165
  • 242

2 Answers2

5

Try this:

:set hls
/^\(.*\)\n\1$
Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110
0

Try the following custom match pattern.

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

Use

:match none

to disable previously defined highlighting.

ib.
  • 27,830
  • 11
  • 80
  • 100