Place the following in your .vimrc file taken from :h :DiffOrig
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis | wincmd p | diffthis
Then when prompted hit o
for ok and then execute :DiffOrig
. You will be presented with the diff.
If you decide that you want to take the file from disk execute :e!
to reload the file from disk.
Quick overview of :DiffOrig
Vertically split a new buffer and read in the file in question from disk and mark both buffers to be diffed.
Glory of detail for :DiffOrig
:vert {cmd}
will execute any {cmd} and any splits will be split vertically.
new
open a new split with a new buffer
set bt=nofile
set 'buftype'
to nofile
so no file will be written to disk
r
is short for :read {file}
. r #
reads in to the buffer the alternative file, which is the buffer that was just split from. This alternative file is the file in question being read from disk.
0d_
which is short for 0delete _
. When the alternative file is read in it leaves a blank line at top. 0delete _
will remove the top line into the black hole register so it does not mess with other registers.
diffthis
set buffer to diffed.
windcmd p
switches back to the previous window. This is the same as <c-w>p
in normal mode.
diffthis
this sets the changed buffer to be included into the diff set.
For more information:
:h :DiffOrig
:h :e
:h :diff
:h vert
:h new
:h r
:h d
:h "_
:h windcmd
:h diffthis
:h :c_#