10 years ago
Open a diff of two registers in a new tabpage. Since this is so quick to invoke it is quite useful when comparing copy-pasta code or when playing spot-the-typo. Pull up the two versions as a real diff in seconds and just close the tabpage when you're finished. If no registers are specified it diffs the most recent yank with the most recent deletion.
" Usage: " :DiffRegs " :DiffRegs @z @x function! DiffRegsFunc(...) let l:left = a:0 == 2 ? a:1 : "@0" let l:right = a:0 == 2 ? a:2 : "@1" tabnew exe 'put! ='. l:left vnew exe 'put! ='. l:right windo setlocal buftype=nofile windo setlocal bufhidden=delete windo setlocal noswapfile windo diffthis winc t endfunction com -nargs=* DiffRegs call DiffRegsFunc(<f-args>)