Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim findfile function usage?

Tags:

vim

I'm looking for an example of how to use the findfile function in a vim script to search upwards recursively for a file, specifically using a wildcard.

Whenever I include a wildcard character as part of the first function parameter this doesn't seem to work.

For example, with the following directory structure:

~/MyProject/
    Test.sln
    src/
      Test.cs

If I run the following function, while editing the file Test.cs with pwd set to ~/MyProject/src

function! Test()
   let a = findfile("*.sln", ".;")
   echo a
endfunction

findfile appears to return nothing. However, if I modify the function to remove the widcard as follows:

function! Test()
   let a = findfile("Test.sln", ".;")
   echo a
endfunction

It does what I would expect.

I've tested this on both ubuntu and windows and I see the same behavior on both. Am I doing something wrong here, or does findfile just not support wildcard characters? A lack of support for the wildcard character seems like a fairly strange omission. It seems like I must be doing something wrong here.

like image 500
actf Avatar asked Jul 23 '11 16:07

actf


1 Answers

If you're using wildcards I think the glob() and/or globpath() functions are what you're looking for. See :h glob() and :h globpath().

like image 75
Herbert Sitz Avatar answered Nov 02 '22 21:11

Herbert Sitz