How to ‘diff’ two subroutines in the same file in Vim?

Nigu picture Nigu · Sep 1, 2010 · Viewed 7.5k times · Source

Is it possible to diff or even vimdiff two very similar subroutines occurring in the same file? If so, how?

I can think of copying the two subroutines in two separate files and then diff them, but is there a way to do it within the original file?

Answer

mMontu picture mMontu · Jan 9, 2012

Plugin linediff.vim : Perform an interactive diff on two blocks of text is similar to the one pointed ou by Vincent with some additional features:

  • has a command to close the opened buffer
  • seems to work without GUI
  • insert some visual indication on the original file(s) being diffed.

To use it you perform a visual selection on the first block to diff, enter command :Linediff, and repeat it to the second block. To quit, :LineDiffReset

I've found the followings maps helpful:

noremap \ldt :Linediff<CR>
noremap \ldo :LinediffReset<CR>