Search code examples
vim

How to diff two lines in an open file in vim?


I occasionally see very long lines in my code that I need to check if they are the same. Is there a way in vim to select two lines and diff them to show any differences between the two?

For example, given the two lines in vim:

AVeryLongReturnType* MyLongClassName:hasAnEvenLongerFunction(That *is, Overloaded *with, Multiple *different, Parameter *lists);
AVeryLongReturnType* MyLongClassName:hasAnEvenLongerFunction(That *is, Overloaded *with, Multiple *different, Parameter *1ists);

I would like vim to tell me that the two lines are in fact different because each spells "lists" differently. Is this possible, and if so, how do I do it?


Solution

  • A quick and dirty solution is to just select both lines and sort them while removing duplicates:

    • select lines
    • ":sort u"
    • if only one line remains, both were equal
    • if both remain, there most be some difference

    An undo recovers everything again.