3

It is easy to use vimscript to determine if a filename was specified to vim by using argc(). Is there a way to determine if the - flag was given to specify piped input was given to vim? It doesn't count piped input as a filename and argc() is empty.

Edit

Thanks to the wonderful accepted answer below, I have a way to open NerdTree if there are no filenames and stndin is not being used.

let wmuse_nt = 0
autocmd StdinReadPost * let wmuse_nt = 1
autocmd vimenter * if !argc() && wmuse_nt == 0 | NERDTree | endif
wmarbut
  • 4,595
  • 7
  • 42
  • 72
  • Nice! I think you should take the "edit" portion out of your question, and instead add it as a self-answer. – yshavit Jun 02 '16 at 22:11

1 Answers1

5

You could use an autocmd to run something before or after vim reads from stdin with the StdinReadPre or StdinReadPost events. The help is copied below.

                                                        StdinReadPost
StdinReadPost                   After reading from the stdin into the buffer,
                                before executing the modelines.  Only used
                                when the "-" argument was used when Vim was
                                started --.
                                                        StdinReadPre
StdinReadPre                    Before reading from stdin into the buffer.
                                Only used when the "-" argument was used when
                                Vim was started --.
FDinoff
  • 30,689
  • 5
  • 75
  • 96