1

all these works

git show bf5500a8 | vim -R - 

vim file1 file2 -O 

git show bf5500a8 > tmpfile ; vim tmpfile  file2 -O ; rm tmpfile 

but I'd like to know if I can open stdout and other file directly , without create a tmp file ?

UPDATE 2021.03.15 : What I really like to know is how vim can replace "-" and use pipe stdout as input. To, for example, open two files in split mode but one came from stdout , Note I'd like use -O option (vertical split mode) and stdout be on left side ...

Thank you

5
  • almost , how I can apply short options like -O ?
    – Sérgio
    Commented Mar 5, 2021 at 9:35
  • vim -O /path/to/file /path/to/file2
    – Sérgio
    Commented Mar 6, 2021 at 13:58
  • ah , ok , as -c prevents the use of "flags" , the answer almost do what I'd like to have ...
    – Sérgio
    Commented Mar 8, 2021 at 10:29
  • Hi, please don't delete your answer , it better than nothing , I don't write well English
    – Sérgio
    Commented Mar 8, 2021 at 14:31
  • I changed my question
    – Sérgio
    Commented Mar 8, 2021 at 14:37

2 Answers 2

1

Try -c which allows you to specify an Ex command to be run after the first file is loaded...

git show bf5500a8 | vim -c 'e /path/to/file' -

You want them in a split?

git show bf5500a8 | vim -c 'split /path/to/file' -

Update: Since you insist on using the -O flag I can show you a trick sort of works from Bash-like shells only but Vim is not intended to be used this way and you may get funky results....

git show bf5500a8 | vim -O /dev/stdin /path/to/file

Note the warning you get.

When you exit and your shell seems unresponsive you can type reset.

Like I said, this is not how Vim is meant to work. If you want to do stream editing you can use Ex mode How can you use vim as a stream editor? ... but you're not going to get a clean result using -O without hacks. You might also look at vipe or vim-stream.

Also, you added the -O requirement after I originally posted a fully working solution to your original question so all of this is really above and beyond the call of duty.

0

The solution

vim <(git show bf5500a8) /path/to/file -O

based on solution to compare two commits https://stackoverflow.com/a/23527631/778517

1
  • FYI that's called Process Substitution. I lumped that under the category of "hacks" due to 1) it only works with certain shells like Bash 2) it's system dependent (OS must support "named pipes" or similar) and 3) the potential for similar problems to other, related solutions...but if it's working well for you I'm glad to hear it.
    – B Layer
    Commented Mar 15, 2021 at 0:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.