I use Vim. I open a file. I edit it and I want to see what I've edited before I save it.
How can I do this in Vim?
I use Vim. I open a file. I edit it and I want to see what I've edited before I save it.
How can I do this in Vim?
Source the following and use :DIFF command
function! s:diff()
let tmpa = tempname()
let tmpb = tempname()
earlier 100h
exec 'w '.tmpa
later 100h
exec 'w '.tmpb
update
exec 'tabnew '.tmpa
diffthis
vert split
exec 'edit '.tmpb
diffthis
endfunction
command! -nargs=0 DIFF call <SID>diff()
from vimrc_example.vim:
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
Not exactly what you're looking for but SCMDiff.vim is really cool. One keypress, and it diff-highlights your current file with the head revision in a source control repo. It's meant to work with many SCMS. I use it with perforce.
I can recommend the histwin plugin.
While it doesn't diff to the current saved version of the file (like the other answers), it can vimdiff changes since you started edting, and even replay your changes in order. The difference shows if you save intermediately.
Additionally, it displays a list of all undo history branches and allows you to switch or diff between them.
PS: While the plugin doesn't automatically track moments in the edit history since every file change, you can explicitly "tag" the moment when you save the file such that you can later vimdiff with it, if you want that. Maybe this could be automated?