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've always likes diffchanges - nice, simple, works.
Follow the above suggests I use git diff that I like much:
:w !git diff % -
If you want to use vim for comparison like in vimdiff, you could do something like this:
Edit your .vimrc and add:
nmap <F8> :w !vim -M -R - -c ":vnew % \| windo diffthis"<CR><CR>
From there on you will see your changes and can quit the diff view using qall
like in vimdiff by pressing F8 in command mode. Replace F8 with any key you like.
Edit: Added -M to disallow any modification, because it is not save.
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
:w !diff % -
There is a plugin, based on different answers here: https://github.com/gangleri/vim-diffsaved
It provides the :w !diff % -
method and the more involved diffthis
one.
Apart from that undotree allows this as well, but also much more (diffs between different undo checkpoints). Similar to Gundo.