I was wondering if there’s a way to see the output of any command,
straight inside vim, rather than first redirecting it into a file and
then opening that file.
E.x. I need something like
$ gvim <
diff -r dir1/ dir2/
This gives ambiguous redirect error message
I just want to see the diffs between dir1 and dir2 straight inside
Can any one provide a nice hack?
diff file1 file2 | vim -R -
-R makes it read-only so you don’t accidentally modify the input (which may or may not be your desired behavior). The single dash tells
vim to reads its input over standard input. Works for other commands, too.
Also, when already in Vim:
:r! diff file1 file2
vim -d file1 file2
Although I would also suggest
vim -d for the case of looking at a diff, I just have to share this (more general) approach for using vim usage in pipes: vipe (from the
moreutils package in Ubuntu).
find -name ‘*.png’ | vipe | xargs rm
would allow you to first edit (in vim) the list of .png files found before passing it to
jst use gvimdiff instead
to paste the output of a command straight into vim, for example ls, try
BTW, there is a DirDiff plugin.
You can do this with
diff -r dir1/ dir2/ | gvim -
-‘ option to vim (or gvim) tells vim to open STDIN
I often use
vimdiff -g <file1> <file2>
One of the most simple and convenient ways is to do it like this:
vimdiff -R <file1> <file2>
Again the ‘-R’ flag is to open it for read-only mode to avoid any accidental changes.
What you are looking for is called process substitution:
vim <(diff -r dir1/ dir2/)
But the DirDiff plugin mentioned by Luc is much more useful for comparing directories.