vimscript 检测管道输入 [英] vimscript detect piped input
问题描述
通过使用argc()
,可以很容易地使用vimscript 来确定是否为vim 指定了文件名.有没有办法确定是否给了 -
标志来指定给 vim 的管道输入?它不会将管道输入计算为文件名,并且 argc()
为空.
编辑
感谢下面接受的精彩答案,如果没有文件名并且没有使用stndin,我有办法打开NerdTree.
让 wmuse_nt = 0autocmd StdinReadPost * 让 wmuse_nt = 1autocmd vimenter * if !argc() &&wmuse_nt == 0 |书呆子树 |万一
你可以使用 autocmd 在 vim 从 stdin 读取之前或之后运行一些StdinReadPre
或 StdinReadPost
事件.帮助复制如下.
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
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 --.
这篇关于vimscript 检测管道输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!