Is there a way to save the changes I made to my vim buffer as a patch file for the original file, without saving it as a separate file and using diff?
It's possible to do this without a plugin using the
w command, so the buffer contents can be used in a shell command:
:w !diff -au "%" - > changes.patch
% is substituted with the path of the file being edited,
- reads the buffer from stdin)
You could also filter the buffer through
diff using the
:%! diff -au "%" -
This will fill the buffer with the diff, rather than writing it to disk; you may want to set
readonly so you don't clobber the original by accident (OTOH, that shouldn't be a serious problem because you have the file under version control, right?). Of course, it helps to have the inverse command:
:%! patch -o - "%"
That transforms your diff back into the modified file.