I know I can enter diff mode in vim by calling diffsplit <filename>
.
I also know I can call an external command and replace the file contents with its output (e.g. in this answer someone uses a json formatting tool by calling :%!python -m json.tool
).
Say I wanted to do something similar, but wanted to see the diff of the current file and the output of the json formatter, and choose which changes to keep. How can I sent the output of the tool to diffsplit
?
Notes:
- I could send the output of the formatter to a file in /tmp or something and then do vimdiff on the file from there. But it would be nice to avoid having to read and write an extra file to/from disk.
- I mainly want to do this for the whole file. If there's a way to send a specific range to the formatter and then diff that range (or diff the result of the command glued into the original file) that would be a nice bonus.
- I am not actually using a json formatter but am looking for a generic solution that would work for this situation (and similar).