0

As title howto source all files under a folder recursively except files that end with .bak

3
  • 2
    This would be simpler if that directory was part of runtimepath and followed conventions. Then you could use runtime with a glob
    – D. Ben Knoble
    Jan 8, 2020 at 13:41
  • Given that the folder is in runtime what would glob would be to achieve the goal? @D.BenKnoble
    – Tuyen Pham
    Jan 9, 2020 at 2:19
  • 2
    for example if they were all in dir, you would use runtime dir/*.vim dir/**/*.vim i think. (Though if you use dir=plugin, and you get that setup before vim loads plugins, it will happen automatically.)
    – D. Ben Knoble
    Jan 9, 2020 at 3:16

2 Answers 2

2

Setting wildignore can have quite a few side effects (especially if done globally).

So I would do:

let s:prefix = '/path/to/folder'

let files = filter(glob(prefix . '/**/*.bak', 1, 1), "fnamemodify(v:val, ':e') != 'bak'")

for fname in files
    execute 'source' fname
endfor
1

You can only 'source' a file at a time. Therefore, build the list of files first, and then source them one by one.

set wildignore=*.bak
let s:prefix = '/path/to/folder'

for s:fname in glob(s:prefix . '/**', 0, 1)
    execute 'source' s:fname
endfor

However, normally you should only source *.vim files, so then it becomes

let s:prefix = '/path/to/folder'

for s:fname in glob(s:prefix . '/**/*.vim', 1, 1)
    execute 'source' s:fname
endfor

But note that file system search does not guarantee order, so there can be some side-effects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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