For example I've the following text:
This is my first line, but longer.
This is my first line
This is my second line, but longer.
This is my second line
This is my third line, but longer.
This is my third line
This
and I expect to remove the shorter lines which share the same (from beginning of the line) content with either previous or next line.
So I'm expect from above example to have only 3 main unique sentences (longer one), as the shorter once are already contained in longer lines. This method has several real usages such as finding the leaf items (such as directories).
Assuming the content is sorted (could be in reverse if that helps), I think we can compare next line with the previous one.
I believe I need to match each line and create some back reference to the previous one, similar as for removing duplicate lines:
:g/^\(.*\)\n\1$/d
but with additional .*
:g/^\(.*\).*\n\1$/d
but it removes the shorter line instead of leaving the longer one.
Any idea how this can be achieved?