You could apply a variant of the Diff recipe:
function! DiffClipboard()
let ft=&ft
vertical new
setlocal bufhidden=wipe buftype=nofile nobuflisted noswapfile
:1put
silent 0d_
diffthis
setlocal nomodifiable
execute "set ft=" . ft
wincmd p
diffthis
endfunction
command! DiffClipboard call DiffClipboard()
let ft=&ft
store the file type of the source buffer in the ft
variable
vertical new
create a new vertical window (aka split)
setlocal bufhidden=wipe butype=nofile nobuflisted noswapfile
make the underlying buffer of the new window a temporary buffer
:1put
paste the content of the default register after line 1 (if you want to use the *
register replace with :1put *
)
slient 0d_
delete the first line of the buffer (the clipboard content starts on line 2)
diffthis
make the buffer part of the diff
set local nomodifiable
make the buffer non modifiable
execute "set ft=" . ft
align the buffer filetype with the source buffer filetype.
wincmd p
switch back to the source buffer
diffthis
make the source buffer part of the diff
Remark: the vertical buffer is created at the right side (if the splitright
option is set) of the source buffer. I you want to switch the order you can add the wincmd r
command after the vertical new
command or unset the splitright
option (:set nosplitright
).
p
in vim. I tried to manually create two documents to diff, but that is more like a workaround, not a solution.