PHA
PHA

Reputation: 1668

mark duplicate lines and exclude characters from the results

I am using this one-liner to find duplicate lines in a text file:

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

When I execute it on C source files, it correctly returns so many { and break; and empty lines. However, they are not the most interesting lines. Howe I can exclude one or multiple characters from the result of this one-liner?

Upvotes: 2

Views: 71

Answers (1)

B.G.
B.G.

Reputation: 6026

Wow that was hard. But i think i got it:

:syn clear Repeat | g/^\(^\(\(\s*break\;\|\s*{\|\s*}\)\@!.\).*\)\n\ze\%(.*\n\)*\1$/exe 'syn match Repeat "^' . escape(getline('.'), '".\^$*[]') . '$"' | nohlsearch

It ignores the following 3 patterns:

\s*break;
\s*}
\s*{

You can ad more in the list separated by \|.

As you can easily spot, it isn't really a nice readable solution. You could improve it with the very magic mode see :h \v. But why do you even need the test for 2 same lines? maybe there is a better solution for your whole usecase

Upvotes: 1

Related Questions