问题
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:
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 --.
来源:https://stackoverflow.com/questions/31548204/vimscript-detect-piped-input