(Fixed a little mistake, added SVN version as well.) |
(Oops, I forgot to remove the horizontal split in the svn version) |
||
Line 42: | Line 42: | ||
let filetype=&ft |
let filetype=&ft |
||
diffthis |
diffthis |
||
− | " new | r # | normal 1Gdd - for horizontal split |
||
vnew | exe "r " . expand("#:h") . ".svn/text-base/" . expand("#:t") . ".svn-base" |
vnew | exe "r " . expand("#:h") . ".svn/text-base/" . expand("#:t") . ".svn-base" |
||
normal 1Gdd |
normal 1Gdd |
Revision as of 18:04, 14 August 2007
Tip: #1030 - Diff current buffer and the original file
Created: October 27, 2005 10:15 Complexity: intermediate Author: Thomas Arendsen Hein - thomas--AT--intevation.de Version: 6.0 Karma: 61/22 Imported from: Tip#1030
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 plugins 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 on vim7 or the nodiff.vim script from script#1198.
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 # normal 1Gd6d 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 "r " . expand("#:h") . ".svn/text-base/" . expand("#:t") . ".svn-base" normal 1Gdd diffthis exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype endfunction com! DiffSVN call s:DiffWithSVNCheckedOut()