Using Vim File Search?

I am looking for an example of using the findfile function in a vim script to search recursively for a file, especially using a wildcard.

Whenever I include a wildcard as part of the first parameter of a function, this does not work.

For example, with the following directory structure:

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

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

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

findfile does not seem to return anything. However, if I change the function to remove the widcard as follows:

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

He does what I expect.

I 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 wildcards? The lack of wildcard support seems a rather strange omission. Looks like I should be doing something wrong.

+6
source share
2 answers

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

+5
source

One way to do this is with an external (quick) find

 function! Test() let l:list=system("find .. -maxdepth 1 -name \*.sln") echo l:list endfunction 
0
source

Source: https://habr.com/ru/post/893418/