tlehman
tlehman

Reputation: 5167

Show vim buffers matching a pattern

In vim, I can show all the open buffers by running the :buffers command, however, sometimes the list can get long, is there a way to limit the output to only filenames matching pattern?

For example:

enter image description here

How would I only show the *.c files?

Upvotes: 5

Views: 636

Answers (2)

Luc Hermitte
Luc Hermitte

Reputation: 32986

You have :buffer *.c^D (where ^D mean you type CTRL+D).

Or, if this is about writing a plugin:

echo join(map(filter(copy(range(1, bufnr('$'))), 'buflisted(v:val) && bufname(v:val) =~ ".*\\.c"'), '" ".fnamemodify(bufname(v:val), ":p")'), "\n")

Upvotes: 4

tivn
tivn

Reputation: 1923

Use Ctrl-D after the wildcard:

:b *.c<Ctrl-D>

Upvotes: 10

Related Questions