Diff current buffer and the original file
From Vim Tips Wiki
Tip 1030 Previous Next Created: October 27, 2005 Complexity: intermediate Author: Thomas Arendsen Hein Version: 6.0
Here is a function/command to see a diff between the currently edited file and its unmodified version in the filesystem. Just put this in your vimrc or in the plugin directory, open a file, make some modifications without saving them, and do :DiffSaved.
function! s:DiffWithSaved() let filetype=&ft diffthis vnew | r # | normal! 1Gdd diffthis exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype endfunction com! DiffSaved call s:DiffWithSaved()
To get out of diff view you can use the :diffoff command.
Below is a similar function, adapted to mimic the 'cvs diff' command (cvs must be in the path):
function! s:DiffWithCVSCheckedOut() let filetype=&ft diffthis vnew | r !cvs up -pr BASE # 1,6d diffthis exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype endfunction com! DiffCVS call s:DiffWithCVSCheckedOut()
Same for svn instead of cvs:
function! s:DiffWithSVNCheckedOut()
let filetype=&ft
diffthis
vnew | exe "%!svn cat " . expand("#:p:h")
diffthis
exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
endfunction
com! DiffSVN call s:DiffWithSVNCheckedOut()
