tags:

views:

284

answers:

7

Hi

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 gvim.

Can any one provide a nice hack?

Thanks Aman Jain

+1  A: 

jst use gvimdiff instead
or vimdiff
to paste the output of a command straight into vim, for example ls, try
:%r!ls

adi92
If you have an alias on `vim` (to a custom installation, maybe), `vimdiff` will use the site-wide vim. You can use `vim -d` (or set up another alias) to get "diff" behavior with your custom vim.
Peter Stone
+13  A: 
diff file1 file2 | vim -R -

The -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.

jvasak
+3  A: 

vim -d file1 file2

Peter Stone
+3  A: 

Also, when already in Vim:

:r! diff file1 file2
skinp
+2  A: 

Although I would also suggest vimdiff or 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).

For example:

find -name '*.png' | vipe | xargs rm

would allow you to first edit (in vim) the list of .png files found before passing it to xargs rm.

Walter
+1  A: 

BTW, there is a DirDiff plugin.

Luc Hermitte
+1  A: 

You can do this with

diff -r dir1/ dir2/ | gvim -

the '-' option to vim (or gvim) tells vim to open STDIN

Nathan Fellman