Search code examples
vimpipeline

How to make read buffer from standard input when run with --remote-tab-silent option?


The following command successfully launches vim that reads the edit buffer from standard input.

echo hi | vim -

But this one does not work.

echo hi | vim --remote-tab-silent -

When the above command is run, the following warning occurs and vim quits.

Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...
Vim: preserving files...
Vim: Finished.

Why does it not read from standard input in the second case?

The help message of vim seems to indicate that it should have worked?

$ vim -h | head
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 31 2015 23:36:07)

usage: vim [arguments] [file ..]       edit specified file(s)
   or: vim [arguments] -               read text from stdin
   or: vim [arguments] -t tag          edit file where tag is defined
   or: vim [arguments] -q [errorfile]  edit file with first error

Arguments:
   --           Only file names after this
   -g           Run using GUI (like "gvim")
$ vim -h | grep remote
   --remote <files> Edit <files> in a Vim server if possible
   --remote-silent <files>  Same, don't complain if there is no server
   --remote-wait <files>  As --remote but wait for files to have been edited
   --remote-wait-silent <files>  Same, don't complain if there is no server
   --remote-tab[-wait][-silent] <files>  As --remote but use tab page per file
   --remote-send <keys> Send <keys> to a Vim server and exit
   --remote-expr <expr> Evaluate <expr> in a Vim server and print result

Solution

  • You cannot edit from stdin when using --remote.

    :h --remote
    

    
     --remote [+{cmd}] {file} ...
                              Open the file list in a remote Vim.  When
                              there is no Vim server, execute locally.
                              There is one optional init command: +{cmd}.
                              This must be an Ex command that can be
                              followed by "|".
                              The rest of the command line is taken as the
                              file list.  Thus any non-file arguments must
                              come before this.
                              You cannot edit stdin this way |--|.
                              The remote Vim is raised.  If you don't want
                              this use >
                               vim --remote-send "<C-\><C-N>:n filename<CR>"

    --remote-silent [+{cmd}] {file} ...
    As above, but don't complain if there is no server and the file is edited locally.

    --remote-tab-silent Like --remote-silent but open each file in a new tabpage.