vimscript detect piped input

情到浓时终转凉″ 提交于 2019-12-11 04:15:04

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!