If there are external changes made to a file being edited in Vim I understand that I can reload the content of the file by :edit
. But, assume that (internally) I've made changes to the file that I want to preserve. Is there a way to integrate the two sets of changes (external and internal)? From what I understand, :edit
simply takes the external changes.
1 Answer
To elaborate on the Christian Brabandt's comment, here is a decomposition of the DiffOrig
command:
Full command:
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
Decomposition:
command DiffOrig " create a new command named DiffOrig
vert new " open a new buffer splitted vertically
| set bt=nofile " set buffer type to scratch
| r # " read the alternate buffer (opened file to diff)
| 0d_ " delete the first line
| diffthis " diff the current buffer
| wincmd p " move cursor to opened file
| diffthis " diff the current buffer
An alternate version use the ++edit
option for the read, it keeps the options values as if editing a file.
References:
:h autoread
? Is that what you're looking for?:autoread
reads in the external changes but in the event that changes are made to the file that is being automatically read, vim will notify me that there have been changes made externally to the file since I have made my internal edits. I am looking for a way to merge the external changes with the internal ones.:h :DiffOrig
?