Is it possible to open vim with stdin in one window, and a file in another?

vim - starts vim with text from stdin in the buffer

vim -o file1 file2 starts vim with files in multiple split windows

Can they be combined? vim -o file1 - doesn't work; it dies with a Too many edit arguments error. I know I can use vim - and then :split file1, but I'd like to do it with command-line flags if possible.

3 Answers 3


Though you cannot use -o, you can execute any commands passed with -c:

$ vim - -c 'split file1'

I just found out another cool way to open from multiple temporary files (without reading from stdin, though):

vim -O <(sort file1) <(sort file2) (split)

vim -p <(sort file1) <(sort file2) (tabbed)

Of course you can execute any command within the brackets:

vim -O <(cat file1) <(cat file2)

(Inspired by https://unix.stackexchange.com/questions/16443/combine-text-files-column-wise)


Based on the synopsis of vim's man page, the answer is no. You may specify multiple files, or a hyphen, but not both:

       vim - Vi IMproved, a programmer's text editor

       vim [options] [file ..]
       vim [options] -
       vim [options] -t tag
       vim [options] -q [errorfile]

One way you may be able to accomplish your goal is using command substitution with file input redirection:

vim -o mine.txt yours.txt <(diff mine.txt yours.txt)

The above command opens three windows in vim:

  1. Regular file: mine.txt
  2. Regular file: yours.txt
  3. Diff the two files, then redirect the output of diff as file input to vim.

The output of <(any command here) is essentially considered by vim to be just another file to be opened.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .