Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show vim buffers matching a pattern

Tags:

regex

vim

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?

like image 780
tlehman Avatar asked Apr 22 '15 16:04

tlehman


2 Answers

Use Ctrl-D after the wildcard:

:b *.c<Ctrl-D>
like image 73
tivn Avatar answered Sep 24 '22 02:09

tivn


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")
like image 24
Luc Hermitte Avatar answered Sep 23 '22 02:09

Luc Hermitte