Tuesday, October 19, 2010

diff this!

Found a cool VIM's command - :diffthis. Invoking it in two different buffers tells the editor to diff the buffers as if it was started as vimdiff. Best (most interesting to me) part is that one can diff two unsaved buffers. E.g.:

" split the screen vertically
:vnew
" paste first code fragment into the left buffer and
:diffthis
" press ^W^W to switch to the right buffer, paste the second code fragment and again call
:diffthis


To cancel the effect of :diffthis one uses the :diffoff command. The command is too buffer specific and has to be invoked in both buffers.

Another interesting related command is :diffpatch {diff-file} which again invokes vimdiff diffing the file currently in buffer against the file with the patch applied.