Thanks to a previous answer, I can test if a file exists using
if !empty(glob("filename"))
...
endif
I now want to check if the file filename
contains text text
.
If possible, I want to do this using native vimscript only, not calling system's grep etc commands.
if filereadable("filename") && match(readfile("filename"),"text")
...
endif
See :help function-list
for a high-level overview of vimscript functions.
I use:
if match(readfile(expand("%:p")),"pattern")!=-1
# content
endif
to check if a file contains a pattern in vimscript
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With