vimscript 检测管道输入
vimscript detect piped input
使用 vim 脚本可以很容易地确定文件名是否通过 argc()
指定为 vim。有没有办法确定是否给了 -
标志来指定管道输入给了 vim?它不将管道输入计为文件名并且 argc()
为空。
编辑
感谢下面接受的精彩回答,如果没有文件名,我有办法打开 NerdTree 并且 stndin 没有被使用。
let wmuse_nt = 0
autocmd StdinReadPost * let wmuse_nt = 1
autocmd vimenter * if !argc() && wmuse_nt == 0 | NERDTree | endif
您可以使用自动命令 运行 在 vim 使用 StdinReadPre
或 StdinReadPost
事件从标准输入读取之前或之后的内容。下面复制帮助。
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 --.
使用 vim 脚本可以很容易地确定文件名是否通过 argc()
指定为 vim。有没有办法确定是否给了 -
标志来指定管道输入给了 vim?它不将管道输入计为文件名并且 argc()
为空。
编辑
感谢下面接受的精彩回答,如果没有文件名,我有办法打开 NerdTree 并且 stndin 没有被使用。
let wmuse_nt = 0
autocmd StdinReadPost * let wmuse_nt = 1
autocmd vimenter * if !argc() && wmuse_nt == 0 | NERDTree | endif
您可以使用自动命令 运行 在 vim 使用 StdinReadPre
或 StdinReadPost
事件从标准输入读取之前或之后的内容。下面复制帮助。
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 --.