开发者

Vim findfile function usage?

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 lik开发者_StackOverflow社区e a fairly strange omission. It seems like I must be doing something wrong here.


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().


One way to do it with external (fast) find

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜