History
Article Edit this page Discussion

Diff current buffer and the original file

From Vim Tips Wiki

Jump to: navigation, search

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()

[edit] Comments

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Diff current buffer and the original file"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation