How can I pare down Vim's buffer list to only include active buffers

Posted by nelstrom on Stack Overflow See other posts from Stack Overflow or by nelstrom
Published on 2010-06-04T12:42:30Z Indexed on 2010/06/06 2:32 UTC
Read the original article Hit count: 273

Filed under:
|

How can I pare down my buffer list to only include buffers that are currently open in a window/tab?

When I've been running Vim for a long time, the list of buffers revealed by the :ls command is too large to work with. Ideally, I would like to delete all of the buffers which are not currently visible in a tab or window by running a custom command such as :Only. Can anybody suggest how to achieve this?

It looks like the :bdelete command can accept a list of buffer numbers, but I'm not sure how to translate the output from :ls to a format that can be consumed by the :bdelete command. Any help would be appreciated.

Clarification

Lets say that in my Vim session I have opened 4 files. The :ls command outputs:

:ls
1  a   "abc.c"
2  h   "123.c"
3  h   "xyz.c"
4  a   "abc.h"

Buffer 1 is in the current tab, and and buffer 4 is in a separate tab, but buffers 2 and 3 are both hidden. I would like to run the command :Only, and it would wipe buffers 2 and 3, so the :ls command would output:

:ls
1  a   "abc.c"
4  a   "abc.h"

This example doesn't make the proposed :Only command look very useful, but if you have a list of 40 buffers it would be very welcome.

© Stack Overflow or respective owner

Related posts about vim

Related posts about vimscript