tags:

views:

42

answers:

2

I'm looking for an elegant way in vimscript to check if file exists in the current directory in a function.

I came up with this but not sure if that's the most elegant solution (I'll be setting vim option if it exists) - is there any way of not having to do another comparison of the filename - maybe use different vim built-in function(?):

:function! SomeCheck()
:   if findfile("SpecificFile", ".") == "SpecificFile"
:       echo "SpecificFile exists"
:   endif
:endfunction
+5  A: 

With a bit of searching in vim man I've found this, which looks much better that the original:

:function! SomeCheck()
:   if filereadable("SpecificFile")
:       echo "SpecificFile exists"
:   endif
:endfunction
stefanB
A: 
:h functions

will give you the exhaustive list of available functions when scripting vim.

Luc Hermitte