简体   繁体   English

如何使用 vimscript 检查文件是否为空?

[英]How do I check if a file is empty using vimscript?

I have written my own linter in vimscript which lints a file using an external linting tool, and then reads the output into the quickfix window.我在 vimscript 中编写了自己的 linter,它使用外部 linting 工具对文件进行 lint,然后将 output 读入 quickfix window。 I want to echo a message if there were no errors, but how can I check if that file is empty to do this?如果没有错误,我想回显一条消息,但是如何检查该文件是否为空来执行此操作?

Usually there's no need to check if temporary file is filereadable() .通常不需要检查临时文件是否为filereadable() So only this should be enough:所以只有这样就足够了:

if getfsize(tempname) < 1
    throw "cannot read temporary file"
endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM