Help! I am looking for a vim script function:

The function takes "currentDirectoryPath" and "fileName"; starting from "currentDirectoryPath" it will search recursively for the existence of "fileName" in the parent directory .

Return true if "fileName" is found and stop searching.

Return false if fileName is not found when reaching root '/'.

Thanks if you can help!

  • 2
    What have you tried? Why is it not working? Where are you stuck? – filbranden Jun 13 '19 at 5:59

You can use findfile() for this.

:echo !empty(findfile(fileName, currentDirectoryPath.';'))

Use :Ag command of the plugin FZF.vim. It is fuzzy regex search, possibly with preview.

  • Note that :Ag is a wrapper around the silver searcher and is better suited to search for text in the current directory rather than testing if a file exists. The appropriate fzf command would be :Files but it still doesn't answer OP's question who isn't looking for a fuzzy finder but for a function taking as argument a full name and returning a boolean. – statox Jun 28 '19 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.