I am trying to ascertain if two blocks of code in the same file are identical. Is there a way to diff two line ranges in Vi/Vim?
I would create two empty buffers (:vnew
, :new
), paste the two line ranges in them and :diffthis
them. You could, for instance, define:
:map q :vnew +put!a^M:new +put!b^M:diffthis^M^W<Down>:diffthis^M
If you want to compare two line ranges, select and yank them in registers a
and b
, respectively, and type q
. This will split your window vertically, split again the new window horizontally, paste registers a
and b
in the two new windows, and diff them.
To simplify a bit you can:
:map q y:vnew +put!a^M:new +put!^M:diffthis^M^W<Down>:diffthis^M
and the second line range will be the one currently selected in visual mode. It saves a few keystrokes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With