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
1
  • Nice! I think you should take the "edit" portion out of your question, and instead add it as a self-answer. Commented Jun 2, 2016 at 22:11

1 Answer 1

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 --.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.