2015-07-21 83 views
2

很容易使用vimscript来确定是否使用argc()将文件名指定为vim。有没有一种方法可以确定-标志是否给出了指定给vim的管道输入?它不会将管道输入作为文件名计数,并且argc()为空。vimscript检测管道输入

编辑

由于下面的精彩接受的答案,我有办法打开NerdTree如果没有文件名没有被使用 stndin。

let wmuse_nt = 0 
autocmd StdinReadPost * let wmuse_nt = 1 
autocmd vimenter * if !argc() && wmuse_nt == 0 | NERDTree | endif 
+0

不错!我认为你应该从你的问题中拿出“编辑”部分,并将其作为自我回答加入。 – yshavit

回答

3

你可以使用一个自动命令之前或之后VIM从与StdinReadPreStdinReadPost事件标准输入读取运行的东西。下面复制帮助。

 
                 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 --.