In the online manual of Vim, :help DiffOrig
will show the recommended command sequence to get changes of current editing file.
Here it is:
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
I wonder what the effect of 0d_ is. I tried 0d_ in normal mode, it works like dd, but I can’t understand why it used here.
Let’s explain it a bit: Suppose you have original foo.txt containing (with line numbers):
You have added a line containing “b” between lines 1 and 2:
:vert newcreates a new, empty, buffer in a vertical split (:help :new):set bt=nofilemakes it a scratch buffer (:help 'bt'). Note::r #inserts after current line, contents of alternate file (#), as stored on the file system. You haven’t saved the other buffer, so you get original content. (:help alternate-file).:help :rtells you that it always inserts after. Therefore::0d_removes the first line. Why0, I don’t know it really, I would ratherwrite it
:1d_.:help rangetells:The
_specifies that it goes to the black-hole register. See:help :dabout the:dex command, it works linewise.The rest is obvious.