I want to redirect the output of some Windows program directly to gvim basically for searching the output. Say for example the result of findstr cmd. Is it possible to do this without dumping it to a file and subsequently loading that file in gvim?
Asked
Active
Viewed 8,923 times
4 Answers
87
sure:
dir | gvim -
the -
option tells vim
to open stdin
This works for Windows and Linux versions.

Nathan Fellman
- 122,701
- 101
- 260
- 319
-
Wow. Must remember this. Cheers Nathan – bfabry May 13 '09 at 06:41
-
@AndresRiofrio: I believe it doesn't. – Nathan Fellman Apr 25 '12 at 09:52
-
1See [this question](http://stackoverflow.com/questions/10311254/how-does-gvim-work-with-remote) for more information on how to get similar behaviour while using `--remote`. – Andres Riofrio Apr 25 '12 at 20:30
-
1Just in case people came here from searching whether this also works for MacVim - yes, it does. `echo 'Testing' | mvim -` – gregoltsov Jul 20 '12 at 08:57
-
Thanx, I was looking for something like that now I have a function for passing the program output to file and terminal: ! xterm -e "node % | gvim -" for js files - now I can even save the output :) Nifty! – Ilian Zapryanov Mar 09 '14 at 19:54
-
Is this behaviour broken after the last Windows 10 update? – cwschmidt Feb 14 '19 at 14:23
-
@cwschmidt I think it was broken by the batch file changing (or perhaps simple the way Windows pipes into batch files) at some point recently, as spelling out the path to gvim.exe still works fine. It continues to work with vim, curiously. – dash-tom-bang May 22 '19 at 22:55
-
@dash-tom-bang The problem went away here, after updating from gvim 7.4 to gvim 8.1 – cwschmidt May 27 '19 at 12:32
23
If you're already in Vim you can use the r
command to read like this:
:r !<cmd>
E.g.
:r !dir

Brian Rasmussen
- 114,645
- 34
- 221
- 317
1
AFAIK, there is no gvim on Mac OS.
If you are using MacVim on mac, this is what I do:
dir | /Applications/MacVim.app/Contents/MacOS/Vim -
When Vim starts in the terminal, then type
<esc>:gui
That should start the MacVim (gui version of vim)

user674669
- 10,681
- 15
- 72
- 105