Heading image for post: Introducing bdubs.vim

Vim

Introducing bdubs.vim

Profile picture of Josh Branchaud

I'm excited to announce my latest edition to our Hashrocket toolbelt, bdubs.vim.

For years, our dotmatrix setup has included a Vim plugin called bufonly.vim. This plugin is not exactly essential, but definitely a very handy addition to our Vim workflow. It allows us to delete all the buffers in a Vim session except for the current one. It has certainly found a place in my brain's collage of Vim keybindings and commands. I've used its :BO command constantly, but come to realize that I need something more.

To help understand why this kind of functionality is useful, I will explain a common scenario. At Hashrocket, we pair on dedicated development machines. We open Vim when we start working on a project and intend to leave it open indefinitely, only closing it on system update or by accident. This means our Vim sessions usually live for days, sometimes even weeks. As you might imagine, as we work on feature after feature in a large code base, the list of buffers hanging around (see :ls!) can grow quite large.

Every once in a while, perhaps in between features, we'd like a clean slate in order to maintain a more useful buffer list. A well-groomed buffer list makes it easier to navigate between and tab-complete buffers that we care about. This is where bufonly.vim comes in. We run :BO and our buffer list gets cleared out. Great!

This plugin served my needs for a long time. As I started to pay attention to some of my pain points though, I realized I needed something more.

First, I prefer to delete buffers with :bwipeout instead of :bdelete. The bufonly.vim plugin only supports :bdelete. This leaves around a ton of unlisted buffers. The :bwipeout command completely removes them.

Second, I've found that deleting all but the current buffer tends to be overkill. I'd prefer to be able to preserve some of the most recently accessed buffers. As I work on a feature, I alternate between source-diving through numerous files and actually editing code in a few files. This means my buffer list gets filled up with a bunch of one-time items with the actual buffers of interest floating to the top. At various points in the development of a feature I usually want to clear out all the noise, but still have access to those recent buffers that I've been iterating on.

I solved both of these issues by writing bdubs.vim.

This plugin provides both the :BD and :BW commands so that I can choose between performing :bdelete and :bwipeout on all the buffers in my Vim session. I prefer to stick with :BW, but :BD is available for those that want to stick with the functionality of bufonly.vim. Additionally, I can append a number to either of these commands. For instance, if I run :BW5, I will wipeout all but the five most recently accessed buffers.

This plugin is now part of our Vim setup. It can be part of yours as well. Check it out on Github and browse the docs for more details on the available commands.

More posts about Vim

  • Adobe logo
  • Barnes and noble logo
  • Aetna logo
  • Vanderbilt university logo
  • Ericsson logo

We're proud to have launched hundreds of products for clients such as LensRentals.com, Engine Yard, Verisign, ParkWhiz, and Regions Bank, to name a few.

Let's talk about your project