vimscript 检测管道输入 [英] vimscript detect piped input

查看:25
本文介绍了vimscript 检测管道输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过使用argc(),可以很容易地使用vimscript 来确定是否为vim 指定了文件名.有没有办法确定是否给了 - 标志来指定给 vim 的管道输入?它不会将管道输入计算为文件名,并且 argc() 为空.

编辑

感谢下面接受的精彩答案,如果没有文件名并且没有使用stndin,我有办法打开NerdTree.

让 wmuse_nt = 0autocmd StdinReadPost * 让 wmuse_nt = 1autocmd vimenter * if !argc() &&wmuse_nt == 0 |书呆子树 |万一

解决方案

你可以使用 autocmd 在 vi​​m 从 stdin 读取之前或之后运行一些StdinReadPreStdinReadPost 事件.帮助复制如下.

<前>标准读后StdinReadPost 从 stdin 读入缓冲区后,在执行模型线之前.仅使用当 Vim 使用 "-" 参数时开始了——.标准读前StdinReadPre 在从 stdin 读入缓冲区之前.仅在使用-"参数时使用Vim 已启动--.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆