2015-07-21 107 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 --.