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
?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityFirst 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)')
Oneliner:
filter(map(getbufinfo({'buflisted': 1}), 'v:val.name'), 'v:val =~ glob2regpat("*.c")')
Dependencies:
getbufinfo() " v7.4.2204
map() " v7.0001
filter() " v7.0001
glob2regpat() " v7.4.673