Closing hidden buffers

4.4
(48)

If you spend a lot of time in Vim, you may end up with dozens or hundreds of open, hidden buffers. A buffer is a file you may have worked in during the current Vim session but stashed away behind the scenes. Over time, having so many open buffers could drag you down. To see your current buffers, just run :buffers.

If you’re like me, you might want to tidy up a bit and close all your hidden buffers. Here’s how:

:up | %bd | e#

First, this updates your current buffer (saves it). Then it closes all open buffers, then it reopens the last buffer. If you want this clean slate regularly, you can create a command from this in your .vimrc:

command Bd :up | %bd | e#

This allows you to run :Bd to close (delete) all other open buffers. Here’s a quick demo of this in action:

For even more control over open buffers and mappings for moving around them, check out the BufExplorer plugin.

How useful was this tip?

Average rating 4.4 / 5. Vote count: 48

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

105 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts