Having a command:

command! -nargs=+ Foo call s:my_fun(<f-args>)

How can I get a glob-match when user say: Foo *met*.c ?

1 Answer 1


First get a list of all buffer names with getbufinfo(), here filtering out non listed:

let buf_list = getbufinfo({'buflisted': 1})

Second use map() to get the names:

let buf_list = map(buf_list, 'v:val.name')

Third filter out names using glob2regpat(), here variable pattern being for-example *.c:

let buf_list = filter(buf_list, 'v:val =~# glob2regpat(pattern)')

If one want buffer-numbers one can further do:

let buf_list = map(buf_list, 'bufnr(v:val)')


filter(map(getbufinfo({'buflisted': 1}), 'v:val.name'), 'v:val =~ glob2regpat("*.c")')


getbufinfo()   " v7.4.2204
map()          " v7.0001
filter()       " v7.0001
glob2regpat()  " v7.4.673

Your Answer

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

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